a digital entity named phi that roams bsky phi.zzstoatzz.io
at main 56 lines 1.5 kB view raw
1"""Regression tests for post splitting (grapheme limit 300).""" 2 3from bot.core.atproto_client import _split_text 4 5 6def test_short_text_unchanged(): 7 assert _split_text("hello world") == ["hello world"] 8 9 10def test_exactly_300_unchanged(): 11 text = "a" * 300 12 assert _split_text(text) == [text] 13 14 15def test_splits_at_sentence_boundary(): 16 # Two sentences, second pushes past 300 17 first = "a" * 250 + "." 18 second = " " + "b" * 100 19 text = first + second 20 chunks = _split_text(text) 21 assert len(chunks) == 2 22 assert chunks[0] == first 23 assert chunks[1] == "b" * 100 24 25 26def test_splits_at_word_boundary(): 27 # No sentence boundaries, should split at last space 28 text = " ".join(["word"] * 100) # 499 chars 29 chunks = _split_text(text) 30 assert all(len(c) <= 300 for c in chunks) 31 assert " ".join(chunks) == text 32 33 34def test_splits_at_paragraph_break(): 35 first = "a" * 200 + "\n" 36 second = "b" * 200 37 text = first + second 38 chunks = _split_text(text) 39 assert len(chunks) == 2 40 assert chunks[0] == "a" * 200 41 assert chunks[1] == "b" * 200 42 43 44def test_three_way_split(): 45 text = ". ".join(["x" * 280] * 3) 46 chunks = _split_text(text) 47 assert len(chunks) == 3 48 assert all(len(c) <= 300 for c in chunks) 49 50 51def test_hard_break_no_spaces(): 52 text = "a" * 600 53 chunks = _split_text(text) 54 assert len(chunks) == 2 55 assert chunks[0] == "a" * 300 56 assert chunks[1] == "a" * 300