Index: tests/regressiontests/utils/tests.py =================================================================== --- tests/regressiontests/utils/tests.py (revision 6401) +++ tests/regressiontests/utils/tests.py (working copy) @@ -7,6 +7,7 @@ from django.utils import html from timesince import timesince_tests +from truncate import truncate_tests class TestUtilsHtml(TestCase): @@ -118,6 +119,7 @@ __test__ = { 'timesince_tests': timesince_tests, + 'truncate_tests': truncate_tests, } if __name__ == "__main__": Index: tests/regressiontests/utils/truncate.py =================================================================== --- tests/regressiontests/utils/truncate.py (revision 0) +++ tests/regressiontests/utils/truncate.py (revision 0) @@ -0,0 +1,32 @@ +truncate_tests = """ +>>> from django.utils.text import truncate_words, truncate_html_words + +>>> text = \"\"\"modo suscipit seacula molestie legere +... duis odio in demonstraverunt eu +... iusto eum elit ea anteposuerit\"\"\" +>>> +>>> html = \"\"\"
modo suscipit seacula molestie legere +... duis odio in demonstraverunt eu +... iusto eum elit ea anteposuerit\"\"\" +>>> + +# truncate_words normalizes line endings to a single space +>>> print truncate_words(text, 10) +modo suscipit seacula molestie legere duis odio in demonstraverunt eu ... + +# truncate_words uses the space to determine word count +# and doesn't deal with html. +>>> print truncate_words(html, 10) +
modo suscipit seacula molestie legere duis odio in demonstraverunt ... + +# tuncate_html_words preserves line endings and html. Tags +# are closed at the end of the newly tuncated text. +>>> print truncate_html_words(text, 10) +modo suscipit seacula molestie legere +duis odio in demonstraverunt eu ... +>>> +>>> print truncate_html_words(html, 10) +
modo suscipit seacula molestie legere +duis odio in demonstraverunt eu ...
+>>> +"""