diff options
| author | Claude Paroz <claude@2xlibre.net> | 2018-08-21 15:28:51 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2018-08-21 17:46:45 +0200 |
| commit | 201017df308266c7d5ed20181e6d0ffa5832e3e9 (patch) | |
| tree | b0ef49951614962cdd7409158ffd06b7f3b9bb55 /tests/utils_tests/test_text.py | |
| parent | 939dcff24f8e97d114595b102fb12348da482135 (diff) | |
Fixed #29654 -- Made text truncation an ellipsis character instead of three dots.
Thanks Sudhanshu Mishra for the initial patch and Tim Graham for the review.
Diffstat (limited to 'tests/utils_tests/test_text.py')
| -rw-r--r-- | tests/utils_tests/test_text.py | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/tests/utils_tests/test_text.py b/tests/utils_tests/test_text.py index 5e12391116..daa028a0f7 100644 --- a/tests/utils_tests/test_text.py +++ b/tests/utils_tests/test_text.py @@ -56,22 +56,22 @@ class TestUtilsText(SimpleTestCase): def test_truncate_chars(self): truncator = text.Truncator('The quick brown fox jumped over the lazy dog.') self.assertEqual('The quick brown fox jumped over the lazy dog.', truncator.chars(100)), - self.assertEqual('The quick brown fox ...', truncator.chars(23)), + self.assertEqual('The quick brown fox …', truncator.chars(21)), self.assertEqual('The quick brown fo.....', truncator.chars(23, '.....')), nfc = text.Truncator('o\xfco\xfco\xfco\xfc') nfd = text.Truncator('ou\u0308ou\u0308ou\u0308ou\u0308') self.assertEqual('oüoüoüoü', nfc.chars(8)) self.assertEqual('oüoüoüoü', nfd.chars(8)) - self.assertEqual('oü...', nfc.chars(5)) - self.assertEqual('oü...', nfd.chars(5)) + self.assertEqual('oü…', nfc.chars(3)) + self.assertEqual('oü…', nfd.chars(3)) # Ensure the final length is calculated correctly when there are # combining characters with no precomposed form, and that combining # characters are not split up. truncator = text.Truncator('-B\u030AB\u030A----8') - self.assertEqual('-B\u030A...', truncator.chars(5)) - self.assertEqual('-B\u030AB\u030A-...', truncator.chars(7)) + self.assertEqual('-B\u030A…', truncator.chars(3)) + self.assertEqual('-B\u030AB\u030A-…', truncator.chars(5)) self.assertEqual('-B\u030AB\u030A----8', truncator.chars(8)) # Ensure the length of the end text is correctly calculated when it @@ -82,18 +82,18 @@ class TestUtilsText(SimpleTestCase): # Make a best effort to shorten to the desired length, but requesting # a length shorter than the ellipsis shouldn't break - self.assertEqual('...', text.Truncator('asdf').chars(1)) + self.assertEqual('…', text.Truncator('asdf').chars(0)) # lazy strings are handled correctly - self.assertEqual(text.Truncator(lazystr('The quick brown fox')).chars(12), 'The quick...') + self.assertEqual(text.Truncator(lazystr('The quick brown fox')).chars(10), 'The quick…') def test_truncate_words(self): truncator = text.Truncator('The quick brown fox jumped over the lazy dog.') self.assertEqual('The quick brown fox jumped over the lazy dog.', truncator.words(10)) - self.assertEqual('The quick brown fox...', truncator.words(4)) + self.assertEqual('The quick brown fox…', truncator.words(4)) self.assertEqual('The quick brown fox[snip]', truncator.words(4, '[snip]')) # lazy strings are handled correctly truncator = text.Truncator(lazystr('The quick brown fox jumped over the lazy dog.')) - self.assertEqual('The quick brown fox...', truncator.words(4)) + self.assertEqual('The quick brown fox…', truncator.words(4)) def test_truncate_html_words(self): truncator = text.Truncator( @@ -104,7 +104,7 @@ class TestUtilsText(SimpleTestCase): truncator.words(10, html=True) ) self.assertEqual( - '<p id="par"><strong><em>The quick brown fox...</em></strong></p>', + '<p id="par"><strong><em>The quick brown fox…</em></strong></p>', truncator.words(4, html=True) ) self.assertEqual( @@ -121,21 +121,21 @@ class TestUtilsText(SimpleTestCase): '<p>The quick <a href="xyz.html"\n id="mylink">brown fox</a> jumped over the lazy dog.</p>' ) self.assertEqual( - '<p>The quick <a href="xyz.html"\n id="mylink">brown...</a></p>', - truncator.words(3, '...', html=True) + '<p>The quick <a href="xyz.html"\n id="mylink">brown…</a></p>', + truncator.words(3, html=True) ) # Test self-closing tags truncator = text.Truncator('<br/>The <hr />quick brown fox jumped over the lazy dog.') - self.assertEqual('<br/>The <hr />quick brown...', truncator.words(3, '...', html=True)) + self.assertEqual('<br/>The <hr />quick brown…', truncator.words(3, html=True)) truncator = text.Truncator('<br>The <hr/>quick <em>brown fox</em> jumped over the lazy dog.') - self.assertEqual('<br>The <hr/>quick <em>brown...</em>', truncator.words(3, '...', html=True)) + self.assertEqual('<br>The <hr/>quick <em>brown…</em>', truncator.words(3, html=True)) # Test html entities truncator = text.Truncator('<i>Buenos días! ¿Cómo está?</i>') - self.assertEqual('<i>Buenos días! ¿Cómo...</i>', truncator.words(3, '...', html=True)) + self.assertEqual('<i>Buenos días! ¿Cómo…</i>', truncator.words(3, html=True)) truncator = text.Truncator('<p>I <3 python, what about you?</p>') - self.assertEqual('<p>I <3 python...</p>', truncator.words(3, '...', html=True)) + self.assertEqual('<p>I <3 python…</p>', truncator.words(3, html=True)) re_tag_catastrophic_test = ('</a' + '\t' * 50000) + '//>' truncator = text.Truncator(re_tag_catastrophic_test) |
