Files
maple/maple-py/tests/test_strings.py
T
2026-05-23 10:17:35 +10:00

31 lines
737 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from maple.pdb.strings import EMPTY, encode_devicesql
def test_empty():
assert encode_devicesql("") == EMPTY
def test_short_ascii():
out = encode_devicesql("ON")
# length=3 -> length_and_kind = (3<<1)|1 = 7
assert out == bytes([7]) + b"ON"
def test_longer_ascii():
s = "Hello, World!"
out = encode_devicesql(s)
length = len(s) + 1
assert out[0] == ((length << 1) | 1)
assert out[1:] == s.encode("ascii")
def test_utf16():
s = "ЛаBа"
out = encode_devicesql(s)
assert out[0] == 0x90
# Total length stored = payload_len + 4
payload = s.encode("utf-16-le")
assert out[1:3] == (len(payload) + 4).to_bytes(2, "little")
assert out[3] == 0
assert out[4:] == payload