Skip to content

Commit

Permalink
Test for std::string_view<char> initialization from Python str
Browse files Browse the repository at this point in the history
  • Loading branch information
wlav committed Feb 18, 2022
1 parent 0073df1 commit 109b865
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ master: 2.3.0
-------------

* CUDA support (up to version 10.2)
* Allow `std::string_view<char>` initialization from Python `str` (copies)
* Provide access to extern "C" declared functions in namespaces
* Support for (multiple and nested) anonymous structs
* Pull forward upstream patch for PPC
Expand Down
37 changes: 37 additions & 0 deletions test/test_stltypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,43 @@ def test01_string_through_string_view(self):
assert countit(v) == 4
assert countit_cr(v) == 4

def test02_string_view_from_unicode(self):
"""Life-time management of converted unicode strings"""

import cppyy, gc

# view on (converted) unicode
text = cppyy.gbl.std.string_view('''\
The standard Lorem Ipsum passage, used since the 1500s
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."\
''')

gc.collect() # likely erases Python-side temporary

assert "Lorem ipsum dolor sit amet" in str(text)

# view on bytes
text = cppyy.gbl.std.string_view(b'''\
The standard Lorem Ipsum passage, used since the 1500s
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."\
''')

gc.collect() # id.

assert "Lorem ipsum dolor sit amet" in str(text)


class TestSTLDEQUE:
def setup_class(cls):
Expand Down

0 comments on commit 109b865

Please sign in to comment.