Skip to content

Commit

Permalink
test_builtin_casters.py test_string_view: Python 2 c++17, c++2a compa…
Browse files Browse the repository at this point in the history
…tibility. (#2314)

Tested with 2.7.18rc1, built with Py_UNICODE_SIZE 4.
Change also tested with Python 3.8.
  • Loading branch information
Ralf W. Grosse-Kunstleve authored Jul 22, 2020
1 parent c4fd1fd commit 96c6763
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions tests/test_builtin_casters.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,24 @@ def test_string_view(capture):
"""Tests support for C++17 string_view arguments and return values"""
assert m.string_view_chars("Hi") == [72, 105]
assert m.string_view_chars("Hi 🎂") == [72, 105, 32, 0xf0, 0x9f, 0x8e, 0x82]
assert m.string_view16_chars("Hi 🎂") == [72, 105, 32, 0xd83c, 0xdf82]
assert m.string_view32_chars("Hi 🎂") == [72, 105, 32, 127874]
assert m.string_view16_chars(u"Hi 🎂") == [72, 105, 32, 0xd83c, 0xdf82]
assert m.string_view32_chars(u"Hi 🎂") == [72, 105, 32, 127874]
if hasattr(m, "has_u8string"):
assert m.string_view8_chars("Hi") == [72, 105]
assert m.string_view8_chars("Hi 🎂") == [72, 105, 32, 0xf0, 0x9f, 0x8e, 0x82]
assert m.string_view8_chars(u"Hi 🎂") == [72, 105, 32, 0xf0, 0x9f, 0x8e, 0x82]

assert m.string_view_return() == "utf8 secret 🎂"
assert m.string_view16_return() == "utf16 secret 🎂"
assert m.string_view32_return() == "utf32 secret 🎂"
assert m.string_view_return() == u"utf8 secret 🎂"
assert m.string_view16_return() == u"utf16 secret 🎂"
assert m.string_view32_return() == u"utf32 secret 🎂"
if hasattr(m, "has_u8string"):
assert m.string_view8_return() == "utf8 secret 🎂"
assert m.string_view8_return() == u"utf8 secret 🎂"

with capture:
m.string_view_print("Hi")
m.string_view_print("utf8 🎂")
m.string_view16_print("utf16 🎂")
m.string_view32_print("utf32 🎂")
assert capture == """
m.string_view16_print(u"utf16 🎂")
m.string_view32_print(u"utf32 🎂")
assert capture == u"""
Hi 2
utf8 🎂 9
utf16 🎂 8
Expand All @@ -158,18 +158,18 @@ def test_string_view(capture):
if hasattr(m, "has_u8string"):
with capture:
m.string_view8_print("Hi")
m.string_view8_print("utf8 🎂")
assert capture == """
m.string_view8_print(u"utf8 🎂")
assert capture == u"""
Hi 2
utf8 🎂 9
"""

with capture:
m.string_view_print("Hi, ascii")
m.string_view_print("Hi, utf8 🎂")
m.string_view16_print("Hi, utf16 🎂")
m.string_view32_print("Hi, utf32 🎂")
assert capture == """
m.string_view16_print(u"Hi, utf16 🎂")
m.string_view32_print(u"Hi, utf32 🎂")
assert capture == u"""
Hi, ascii 9
Hi, utf8 🎂 13
Hi, utf16 🎂 12
Expand All @@ -178,8 +178,8 @@ def test_string_view(capture):
if hasattr(m, "has_u8string"):
with capture:
m.string_view8_print("Hi, ascii")
m.string_view8_print("Hi, utf8 🎂")
assert capture == """
m.string_view8_print(u"Hi, utf8 🎂")
assert capture == u"""
Hi, ascii 9
Hi, utf8 🎂 13
"""
Expand Down

0 comments on commit 96c6763

Please sign in to comment.