2021-04-01 23:03:49 +00:00
|
|
|
from pyo3_pytests.buf_and_str import BytesExtractor
|
2019-09-07 08:59:19 +00:00
|
|
|
|
2019-09-21 17:06:20 +00:00
|
|
|
|
2021-07-18 19:03:45 +00:00
|
|
|
def test_extract_bytes():
|
2019-09-07 08:59:19 +00:00
|
|
|
extractor = BytesExtractor()
|
2021-07-18 19:03:45 +00:00
|
|
|
message = b'\\(-"-;) A message written in bytes'
|
|
|
|
assert extractor.from_bytes(message) == len(message)
|
2019-09-07 08:59:19 +00:00
|
|
|
|
|
|
|
|
2021-07-18 19:03:45 +00:00
|
|
|
def test_extract_str():
|
|
|
|
extractor = BytesExtractor()
|
|
|
|
message = '\\(-"-;) A message written as a string'
|
|
|
|
assert extractor.from_str(message) == len(message)
|
2019-10-21 13:48:01 +00:00
|
|
|
|
2019-09-07 08:59:19 +00:00
|
|
|
|
2021-07-18 19:03:45 +00:00
|
|
|
def test_extract_str_lossy():
|
|
|
|
extractor = BytesExtractor()
|
|
|
|
message = '\\(-"-;) A message written with a trailing surrogate \ud800'
|
|
|
|
rust_surrogate_len = extractor.from_str_lossy("\ud800")
|
|
|
|
assert extractor.from_str_lossy(message) == len(message) - 1 + rust_surrogate_len
|