PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/utils/text.py

https://code.google.com/p/mango-py/
Python | 40 lines | 32 code | 8 blank | 0 comment | 0 complexity | ba5f3ae70bbdfe6394433b075d832f24 MD5 | raw file
 1import unittest
 2
 3from django.utils import text
 4
 5class TestUtilsText(unittest.TestCase):
 6
 7    def test_truncate_words(self):
 8        self.assertEqual(u'The quick brown fox jumped over the lazy dog.',
 9            text.truncate_words(u'The quick brown fox jumped over the lazy dog.', 10))
10        self.assertEqual(u'The quick brown fox ...',
11            text.truncate_words('The quick brown fox jumped over the lazy dog.', 4))
12        self.assertEqual(u'The quick brown fox ....',
13            text.truncate_words('The quick brown fox jumped over the lazy dog.', 4, '....'))
14
15    def test_truncate_html_words(self):
16        self.assertEqual(u'<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>',
17            text.truncate_html_words('<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>', 10))
18        self.assertEqual(u'<p><strong><em>The quick brown fox ...</em></strong></p>',
19            text.truncate_html_words('<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>', 4))
20        self.assertEqual(u'<p><strong><em>The quick brown fox ....</em></strong></p>',
21            text.truncate_html_words('<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>', 4, '....'))
22        self.assertEqual(u'<p><strong><em>The quick brown fox</em></strong></p>',
23            text.truncate_html_words('<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>', 4, None))
24
25    def test_wrap(self):
26        digits = '1234 67 9'
27        self.assertEqual(text.wrap(digits, 100), u'1234 67 9')
28        self.assertEqual(text.wrap(digits, 9), u'1234 67 9')
29        self.assertEqual(text.wrap(digits, 8), u'1234 67\n9')
30
31        self.assertEqual(text.wrap('short\na long line', 7),
32                         u'short\na long\nline')
33
34        self.assertEqual(text.wrap('do-not-break-long-words please? ok', 8),
35                         u'do-not-break-long-words\nplease?\nok')
36
37        long_word = 'l%sng' % ('o' * 20)
38        self.assertEqual(text.wrap(long_word, 20), long_word)
39        self.assertEqual(text.wrap('a %s word' % long_word, 10),
40                         u'a\n%s\nword' % long_word)