Tests the ability to pass bytes to C++ string-accepting functions. Note that this is one-way: the only way to return bytes to Python is via the pybind11::bytes class.
()
| 122 | |
| 123 | |
| 124 | def test_bytes_to_string(): |
| 125 | """Tests the ability to pass bytes to C++ string-accepting functions. Note that this is |
| 126 | one-way: the only way to return bytes to Python is via the pybind11::bytes class.""" |
| 127 | # Issue #816 |
| 128 | |
| 129 | assert m.strlen(b"hi") == 2 |
| 130 | assert m.string_length(b"world") == 5 |
| 131 | assert m.string_length(b"a\x00b") == 3 |
| 132 | assert m.strlen(b"a\x00b") == 1 # C-string limitation |
| 133 | |
| 134 | # passing in a utf8 encoded string should work |
| 135 | assert m.string_length("💩".encode()) == 4 |
| 136 | |
| 137 | |
| 138 | def test_bytearray_to_string(): |
nothing calls this directly
no outgoing calls
no test coverage detected