# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.template.defaultfilters import truncatewords_html from django.test import SimpleTestCase class FunctionTests(SimpleTestCase): def test_truncate_zero(self): self.assertEqual(truncatewords_html('

one two - three
four
five

', 0), '') def test_truncate(self): self.assertEqual( truncatewords_html('

one two - three
four
five

', 2), '

one two ...

', ) def test_truncate2(self): self.assertEqual( truncatewords_html('

one two - three
four
five

', 4), '

one two - three
four ...

', ) def test_truncate3(self): self.assertEqual( truncatewords_html('

one two - three
four
five

', 5), '

one two - three
four
five

', ) def test_truncate4(self): self.assertEqual( truncatewords_html('

one two - three
four
five

', 100), '

one two - three
four
five

', ) def test_truncate_unicode(self): self.assertEqual(truncatewords_html('\xc5ngstr\xf6m was here', 1), '\xc5ngstr\xf6m ...') def test_truncate_complex(self): self.assertEqual( truncatewords_html('Buenos días! ¿Cómo está?', 3), 'Buenos días! ¿Cómo ...', )