@@ -85,6 +85,17 @@ def test_truncate_chars(self):
8585 # lazy strings are handled correctly
8686 self .assertEqual (text .Truncator (lazystr ('The quick brown fox' )).chars (12 ), 'The quick...' )
8787
88+ def test_truncate_chars_html (self ):
89+ perf_test_values = [
90+ (('</a' + '\t ' * 50000 ) + '//>' , None ),
91+ ('&' * 50000 , '&' * 7 + '...' ),
92+ ('_X<<<<<<<<<<<>' , None ),
93+ ]
94+ for value , expected in perf_test_values :
95+ with self .subTest (value = value ):
96+ truncator = text .Truncator (value )
97+ self .assertEqual (expected if expected else value , truncator .chars (10 , html = True ))
98+
8899 def test_truncate_words (self ):
89100 truncator = text .Truncator ('The quick brown fox jumped over the lazy dog.' )
90101 self .assertEqual ('The quick brown fox jumped over the lazy dog.' , truncator .words (10 ))
@@ -134,11 +145,17 @@ def test_truncate_html_words(self):
134145 truncator = text .Truncator ('<i>Buenos días! ¿Cómo está?</i>' )
135146 self .assertEqual ('<i>Buenos días! ¿Cómo...</i>' , truncator .words (3 , '...' , html = True ))
136147 truncator = text .Truncator ('<p>I <3 python, what about you?</p>' )
137- self .assertEqual ('<p>I <3 python...</p>' , truncator .words (3 , '...' , html = True ))
148+ self .assertEqual ('<p>I <3 python, ...</p>' , truncator .words (3 , '...' , html = True ))
138149
139- re_tag_catastrophic_test = ('</a' + '\t ' * 50000 ) + '//>'
140- truncator = text .Truncator (re_tag_catastrophic_test )
141- self .assertEqual (re_tag_catastrophic_test , truncator .words (500 , html = True ))
150+ perf_test_values = [
151+ ('</a' + '\t ' * 50000 ) + '//>' ,
152+ '&' * 50000 ,
153+ '_X<<<<<<<<<<<>' ,
154+ ]
155+ for value in perf_test_values :
156+ with self .subTest (value = value ):
157+ truncator = text .Truncator (value )
158+ self .assertEqual (value , truncator .words (50 , html = True ))
142159
143160 def test_wrap (self ):
144161 digits = '1234 67 9'
0 commit comments