Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/template_tests/filter_tests/test_truncatechars_html.py
blob: cf2623d7405084e82513d37defec5800c98201ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.template.defaultfilters import truncatechars_html
from django.test import SimpleTestCase


class FunctionTests(SimpleTestCase):

    def test_truncate_zero(self):
        self.assertEqual(truncatechars_html('<p>one <a href="#">two - three <br>four</a> five</p>', 0), '...')

    def test_truncate(self):
        self.assertEqual(
            truncatechars_html('<p>one <a href="#">two - three <br>four</a> five</p>', 6),
            '<p>one...</p>',
        )

    def test_truncate2(self):
        self.assertEqual(
            truncatechars_html('<p>one <a href="#">two - three <br>four</a> five</p>', 11),
            '<p>one <a href="#">two ...</a></p>',
        )

    def test_truncate3(self):
        self.assertEqual(
            truncatechars_html('<p>one <a href="#">two - three <br>four</a> five</p>', 100),
            '<p>one <a href="#">two - three <br>four</a> five</p>',
        )

    def test_truncate_unicode(self):
        self.assertEqual(truncatechars_html('<b>\xc5ngstr\xf6m</b> was here', 5), '<b>\xc5n...</b>')

    def test_truncate_something(self):
        self.assertEqual(truncatechars_html('a<b>b</b>c', 3), 'a<b>b</b>c')