Renamed to lorabot
This commit is contained in:
+59
-1
@@ -1,4 +1,4 @@
|
||||
from meshbot.messages import trim_to_bytes
|
||||
from lorabot.messages import split_to_bytes, trim_to_bytes
|
||||
|
||||
|
||||
def test_short_ascii_passthrough():
|
||||
@@ -38,3 +38,61 @@ def test_zero_or_negative_max_bytes():
|
||||
|
||||
def test_empty_input():
|
||||
assert trim_to_bytes("", 184) == ""
|
||||
|
||||
|
||||
# split_to_bytes
|
||||
|
||||
|
||||
def test_split_short_input_single_chunk():
|
||||
assert split_to_bytes("hello", 184) == ["hello"]
|
||||
|
||||
|
||||
def test_split_long_input_two_chunks_drops_rest():
|
||||
s = "x" * 500
|
||||
chunks = split_to_bytes(s, 180, max_chunks=2)
|
||||
assert chunks == ["x" * 180, "x" * 180]
|
||||
assert sum(len(c.encode("utf-8")) for c in chunks) == 360
|
||||
|
||||
|
||||
def test_split_exact_two_chunks_no_third():
|
||||
s = "x" * 360
|
||||
chunks = split_to_bytes(s, 180, max_chunks=2)
|
||||
assert chunks == ["x" * 180, "x" * 180]
|
||||
|
||||
|
||||
def test_split_does_not_break_multibyte():
|
||||
# 4 emoji × 4 bytes = 16 bytes total. Budget 5 bytes/chunk → 1 emoji per chunk.
|
||||
chunks = split_to_bytes("🎉🎉🎉🎉", 5, max_chunks=2)
|
||||
assert chunks == ["🎉", "🎉"]
|
||||
for c in chunks:
|
||||
assert len(c.encode("utf-8")) == 4
|
||||
|
||||
|
||||
def test_split_two_byte_char_at_boundary():
|
||||
# "abäcd" → bytes: a b ä(2) c d = 6 bytes. Budget 3/chunk:
|
||||
# chunk1 must end at "ab" (3rd byte is start of ä, can't include without continuation).
|
||||
# chunk2: "äc" = 3 bytes.
|
||||
chunks = split_to_bytes("abäcd", 3, max_chunks=2)
|
||||
assert chunks[0] == "ab"
|
||||
assert chunks[1] == "äc"
|
||||
# "d" is dropped (over the budget).
|
||||
|
||||
|
||||
def test_split_empty_input():
|
||||
assert split_to_bytes("", 184) == []
|
||||
|
||||
|
||||
def test_split_zero_max_bytes():
|
||||
assert split_to_bytes("hi", 0) == []
|
||||
|
||||
|
||||
def test_split_zero_chunks():
|
||||
assert split_to_bytes("hi", 184, max_chunks=0) == []
|
||||
|
||||
|
||||
def test_split_concat_is_prefix_of_input():
|
||||
# The delivered text must always be a prefix of the original (no rearrangement).
|
||||
src = "Hello world! 🎉 This is a longer message that should be split."
|
||||
chunks = split_to_bytes(src, 20, max_chunks=2)
|
||||
delivered = "".join(chunks)
|
||||
assert src.startswith(delivered)
|
||||
|
||||
Reference in New Issue
Block a user