@@ -6,22 +6,136 @@ class TestMastodonCaption:
66 def setup_method (self ):
77 self .poster = PosterMastodon .__new__ (PosterMastodon )
88
9+ def reconstruct_text (self , main_caption : str , replies : list [str ]) -> str :
10+ main_without_tags = main_caption .split ("\n \n #" )[0 ]
11+ main_without_suffix = (
12+ main_without_tags
13+ .replace ("..." , "" )
14+ .replace ("\n \n More details below ⬇️" , "" )
15+ .strip ()
16+ )
17+
18+ return " " .join ([main_without_suffix ] + replies ).strip ()
19+
20+ def test_thread_preserves_original_text_content (self ):
21+ original_text = " " .join (f"word{ i } " for i in range (300 ))
22+ post = Post (text = original_text , tags = ["AdoptDontShop" , "Boston" ])
23+
24+ main_caption , replies = self .poster ._format_caption_thread (post )
25+
26+ reconstructed = self .reconstruct_text (main_caption , replies )
27+
28+ assert reconstructed == original_text
29+
30+ def test_thread_preserves_original_text_without_spaces (self ):
31+ original_text = "x" * 1000
32+ post = Post (text = original_text , tags = ["AdoptDontShop" , "Boston" ])
33+
34+ main_caption , replies = self .poster ._format_caption_thread (post )
35+
36+ main_without_tags = main_caption .split ("\n \n #" )[0 ]
37+ main_without_suffix = (
38+ main_without_tags
39+ .replace ("..." , "" )
40+ .replace ("\n \n More details below ⬇️" , "" )
41+ .strip ()
42+ )
43+
44+ reconstructed = main_without_suffix + "" .join (replies )
45+
46+ assert reconstructed == original_text
47+
948 def test_no_tags (self ):
1049 post = Post (text = "Hello, world!" )
11- assert self .poster ._format_caption (post ) == "Hello, world!"
50+ main_caption , replies = self .poster ._format_caption_thread (post )
51+ assert main_caption == "Hello, world!"
52+ assert replies == []
1253
1354 def test_with_tags (self ):
1455 post = Post (text = "Meet Poppy!" , tags = ["AdoptDontShop" , "Boston" ])
15- assert self .poster ._format_caption (post ) == "Meet Poppy!\n \n #AdoptDontShop #Boston"
56+ main_caption , replies = self .poster ._format_caption_thread (post )
57+
58+ assert main_caption == "Meet Poppy!\n \n #AdoptDontShop #Boston"
59+ assert replies == []
1660
17- def test_caption_stays_under_limit (self ):
61+ def test_caption_stays_under_limit_and_creates_reply (self ):
62+ post = Post (text = "x " * 1000 , tags = ["AdoptDontShop" , "Boston" ])
63+ main_caption , replies = self .poster ._format_caption_thread (post )
64+
65+ assert len (main_caption ) <= MASTODON_CHARACTER_LIMIT
66+ assert main_caption .endswith ("\n \n #AdoptDontShop #Boston" )
67+ assert "..." in main_caption
68+ assert "More details below" in main_caption
69+ assert replies
70+ assert all (len (reply ) <= MASTODON_CHARACTER_LIMIT for reply in replies )
71+
72+ def test_caption_stays_under_limit_creates_reply (self ):
1873 post = Post (text = "x" * 1000 , tags = ["AdoptDontShop" , "Boston" ])
19- caption = self .poster ._format_caption (post )
74+ main_caption , replies = self .poster ._format_caption_thread (post )
2075
21- assert len (caption ) <= MASTODON_CHARACTER_LIMIT
22- assert caption .endswith ("\n \n #AdoptDontShop #Boston" )
23- assert "..." in caption
76+ assert len (main_caption ) <= MASTODON_CHARACTER_LIMIT
77+ assert main_caption .endswith ("\n \n #AdoptDontShop #Boston" )
78+ assert "..." in main_caption
79+ assert "More details below" in main_caption
80+ assert replies
81+ assert all (len (reply ) <= MASTODON_CHARACTER_LIMIT for reply in replies )
2482
2583 def test_empty_tags_are_ignored (self ):
2684 post = Post (text = "Meet Poppy!" , tags = ["AdoptDontShop" , "" , None , "Boston" ])
27- assert self .poster ._format_caption (post ) == "Meet Poppy!\n \n #AdoptDontShop #Boston"
85+ main_caption , replies = self .poster ._format_caption_thread (post )
86+
87+ assert main_caption == "Meet Poppy!\n \n #AdoptDontShop #Boston"
88+ assert replies == []
89+
90+ def test_long_text_without_tags_creates_replies (self ):
91+ post = Post (text = "hello " * 300 )
92+ main_caption , replies = self .poster ._format_caption_thread (post )
93+
94+ assert len (main_caption ) <= MASTODON_CHARACTER_LIMIT
95+ assert replies
96+ assert all (len (reply ) <= MASTODON_CHARACTER_LIMIT for reply in replies )
97+
98+ def test_safe_truncate_does_not_split_words_when_possible (self ):
99+ kept , remaining = self .poster ._safe_truncate ("hello world again" , 12 )
100+ assert kept == "hello world"
101+ assert remaining == "again"
102+
103+
104+
105+
106+
107+
108+
109+
110+
111+
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
122+
123+
124+
125+
126+
127+
128+
129+
130+
131+
132+
133+
134+
135+
136+
137+
138+
139+
140+
141+
0 commit comments