test_builtin_casters.py test_string_view: Python 2 c++17, c++2a compatibility. (#2314)

Tested with 2.7.18rc1, built with Py_UNICODE_SIZE 4.
Change also tested with Python 3.8.
This commit is contained in:
Ralf W. Grosse-Kunstleve 2020-07-22 12:05:16 -07:00 committed by GitHub
parent c4fd1fd987
commit 96c6763613
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -132,24 +132,24 @@ def test_string_view(capture):
"""Tests support for C++17 string_view arguments and return values""" """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]
assert m.string_view_chars("Hi 🎂") == [72, 105, 32, 0xf0, 0x9f, 0x8e, 0x82] 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_view16_chars(u"Hi 🎂") == [72, 105, 32, 0xd83c, 0xdf82]
assert m.string_view32_chars("Hi 🎂") == [72, 105, 32, 127874] assert m.string_view32_chars(u"Hi 🎂") == [72, 105, 32, 127874]
if hasattr(m, "has_u8string"): if hasattr(m, "has_u8string"):
assert m.string_view8_chars("Hi") == [72, 105] 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_view_return() == u"utf8 secret 🎂"
assert m.string_view16_return() == "utf16 secret 🎂" assert m.string_view16_return() == u"utf16 secret 🎂"
assert m.string_view32_return() == "utf32 secret 🎂" assert m.string_view32_return() == u"utf32 secret 🎂"
if hasattr(m, "has_u8string"): if hasattr(m, "has_u8string"):
assert m.string_view8_return() == "utf8 secret 🎂" assert m.string_view8_return() == u"utf8 secret 🎂"
with capture: with capture:
m.string_view_print("Hi") m.string_view_print("Hi")
m.string_view_print("utf8 🎂") m.string_view_print("utf8 🎂")
m.string_view16_print("utf16 🎂") m.string_view16_print(u"utf16 🎂")
m.string_view32_print("utf32 🎂") m.string_view32_print(u"utf32 🎂")
assert capture == """ assert capture == u"""
Hi 2 Hi 2
utf8 🎂 9 utf8 🎂 9
utf16 🎂 8 utf16 🎂 8
@ -158,8 +158,8 @@ def test_string_view(capture):
if hasattr(m, "has_u8string"): if hasattr(m, "has_u8string"):
with capture: with capture:
m.string_view8_print("Hi") m.string_view8_print("Hi")
m.string_view8_print("utf8 🎂") m.string_view8_print(u"utf8 🎂")
assert capture == """ assert capture == u"""
Hi 2 Hi 2
utf8 🎂 9 utf8 🎂 9
""" """
@ -167,9 +167,9 @@ def test_string_view(capture):
with capture: with capture:
m.string_view_print("Hi, ascii") m.string_view_print("Hi, ascii")
m.string_view_print("Hi, utf8 🎂") m.string_view_print("Hi, utf8 🎂")
m.string_view16_print("Hi, utf16 🎂") m.string_view16_print(u"Hi, utf16 🎂")
m.string_view32_print("Hi, utf32 🎂") m.string_view32_print(u"Hi, utf32 🎂")
assert capture == """ assert capture == u"""
Hi, ascii 9 Hi, ascii 9
Hi, utf8 🎂 13 Hi, utf8 🎂 13
Hi, utf16 🎂 12 Hi, utf16 🎂 12
@ -178,8 +178,8 @@ def test_string_view(capture):
if hasattr(m, "has_u8string"): if hasattr(m, "has_u8string"):
with capture: with capture:
m.string_view8_print("Hi, ascii") m.string_view8_print("Hi, ascii")
m.string_view8_print("Hi, utf8 🎂") m.string_view8_print(u"Hi, utf8 🎂")
assert capture == """ assert capture == u"""
Hi, ascii 9 Hi, ascii 9
Hi, utf8 🎂 13 Hi, utf8 🎂 13
""" """