diff options
| author | David Smith <smithdc@gmail.com> | 2024-02-06 20:52:52 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2024-02-07 05:18:35 +0100 |
| commit | 70f39e46f86b946c273340d52109824c776ffb4c (patch) | |
| tree | 59c7d77d33d8fd61b467107029c5f3fdef27f742 /tests/utils_tests/test_text.py | |
| parent | 3e820d10f81ea9d0576633734c2ebd2621575cbe (diff) | |
Refs #30686 -- Fixed text truncation for negative or zero lengths.
Diffstat (limited to 'tests/utils_tests/test_text.py')
| -rw-r--r-- | tests/utils_tests/test_text.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/tests/utils_tests/test_text.py b/tests/utils_tests/test_text.py index a7f25c7936..6004712bf2 100644 --- a/tests/utils_tests/test_text.py +++ b/tests/utils_tests/test_text.py @@ -89,7 +89,7 @@ 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(0)) + self.assertEqual("...", text.Truncator("asdf").chars(1, truncate="...")) # lazy strings are handled correctly self.assertEqual( text.Truncator(lazystr("The quick brown fox")).chars(10), "The quick…" @@ -123,6 +123,8 @@ class TestUtilsText(SimpleTestCase): "…", truncator.chars(1, html=True), ) + self.assertEqual("", truncator.chars(0, html=True)) + self.assertEqual("", truncator.chars(-1, html=True)) self.assertEqual( '<p id="par"><strong><em>The qu....</em></strong></p>', truncator.chars(10, "....", html=True), @@ -206,6 +208,8 @@ class TestUtilsText(SimpleTestCase): lazystr("The quick brown fox jumped over the lazy dog.") ) self.assertEqual("The quick brown fox…", truncator.words(4)) + self.assertEqual("", truncator.words(0)) + self.assertEqual("", truncator.words(-1)) def test_truncate_html_words(self): truncator = text.Truncator( |
