PageRenderTime 41ms CodeModel.GetById 35ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause
  1. import unittest
  2. from django.utils import text
  3. class TestUtilsText(unittest.TestCase):
  4. def test_truncate_words(self):
  5. self.assertEqual(u'The quick brown fox jumped over the lazy dog.',
  6. text.truncate_words(u'The quick brown fox jumped over the lazy dog.', 10))
  7. self.assertEqual(u'The quick brown fox ...',
  8. text.truncate_words('The quick brown fox jumped over the lazy dog.', 4))
  9. self.assertEqual(u'The quick brown fox ....',
  10. text.truncate_words('The quick brown fox jumped over the lazy dog.', 4, '....'))
  11. def test_truncate_html_words(self):
  12. self.assertEqual(u'<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>',
  13. text.truncate_html_words('<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>', 10))
  14. self.assertEqual(u'<p><strong><em>The quick brown fox ...</em></strong></p>',
  15. text.truncate_html_words('<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>', 4))
  16. self.assertEqual(u'<p><strong><em>The quick brown fox ....</em></strong></p>',
  17. text.truncate_html_words('<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>', 4, '....'))
  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, None))
  20. def test_wrap(self):
  21. digits = '1234 67 9'
  22. self.assertEqual(text.wrap(digits, 100), u'1234 67 9')
  23. self.assertEqual(text.wrap(digits, 9), u'1234 67 9')
  24. self.assertEqual(text.wrap(digits, 8), u'1234 67\n9')
  25. self.assertEqual(text.wrap('short\na long line', 7),
  26. u'short\na long\nline')
  27. self.assertEqual(text.wrap('do-not-break-long-words please? ok', 8),
  28. u'do-not-break-long-words\nplease?\nok')
  29. long_word = 'l%sng' % ('o' * 20)
  30. self.assertEqual(text.wrap(long_word, 20), long_word)
  31. self.assertEqual(text.wrap('a %s word' % long_word, 10),
  32. u'a\n%s\nword' % long_word)