Ticket #1919: truncate_tests.diff

File truncate_tests.diff, 2.0 KB (added by deryck, 17 years ago)

Tests for django.utils.text.trunacte_*.

  • tests/regressiontests/utils/tests.py

     
    77from django.utils import html
    88
    99from timesince import timesince_tests
     10from truncate import truncate_tests
    1011
    1112class TestUtilsHtml(TestCase):
    1213
     
    118119
    119120__test__ = {
    120121    'timesince_tests': timesince_tests,
     122    'truncate_tests': truncate_tests,
    121123}
    122124
    123125if __name__ == "__main__":
  • tests/regressiontests/utils/truncate.py

     
     1truncate_tests = """
     2>>> from django.utils.text import truncate_words, truncate_html_words
     3
     4>>> text = \"\"\"modo suscipit seacula molestie legere
     5... duis odio in demonstraverunt eu
     6... iusto eum elit ea anteposuerit\"\"\"
     7>>>
     8>>> html = \"\"\"<p>modo suscipit <a href="/somelink/">seacula</a> molestie legere
     9... duis odio in demonstraverunt <strong>eu</strong>
     10... iusto eum elit ea anteposuerit\"\"\"
     11>>>
     12
     13# truncate_words normalizes line endings to a single space
     14>>> print truncate_words(text, 10)
     15modo suscipit seacula molestie legere duis odio in demonstraverunt eu ...
     16
     17# truncate_words uses the space to determine word count
     18# and doesn't deal with html.
     19>>> print truncate_words(html, 10)
     20<p>modo suscipit <a href="/somelink/">seacula</a> molestie legere duis odio in demonstraverunt ...
     21
     22# tuncate_html_words preserves line endings and html.  Tags
     23# are closed at the end of the newly tuncated text.
     24>>> print truncate_html_words(text, 10)
     25modo suscipit seacula molestie legere
     26duis odio in demonstraverunt eu ...
     27>>>
     28>>> print truncate_html_words(html, 10)
     29<p>modo suscipit <a href="/somelink/">seacula</a> molestie legere
     30duis odio in demonstraverunt <strong>eu ...</strong></p>
     31>>>
     32"""
Back to Top