summaryrefslogtreecommitdiffstats
path: root/tests/test_slugify.py
blob: c910aaa2ad08603282ec720289baaccf8818a55d (plain) (blame)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-

u"""Test slugify."""

from __future__ import unicode_literals
import nikola.utils


def test_ascii():
    """Test an ASCII-only string."""
    o = nikola.utils.slugify(u'hello', lang='en')
    assert o == u'hello'
    assert isinstance(o, nikola.utils.unicode_str)


def test_ascii_dash():
    """Test an ASCII string, with dashes."""
    o = nikola.utils.slugify(u'hello-world', lang='en')
    assert o == u'hello-world'
    assert isinstance(o, nikola.utils.unicode_str)


def test_ascii_fancy():
    """Test an ASCII string, with fancy characters."""
    o = nikola.utils.slugify(u'The quick brown fox jumps over the lazy dog!-123.456', lang='en')
    assert o == u'the-quick-brown-fox-jumps-over-the-lazy-dog-123456'
    assert isinstance(o, nikola.utils.unicode_str)


def test_pl():
    """Test a string with Polish diacritical characters."""
    o = nikola.utils.slugify(u'zażółćgęśląjaźń', lang='pl')
    assert o == u'zazolcgeslajazn'
    assert isinstance(o, nikola.utils.unicode_str)


def test_pl_dash():
    """Test a string with Polish diacritical characters and dashes."""
    o = nikola.utils.slugify(u'zażółć-gęślą-jaźń', lang='pl')
    assert o == u'zazolc-gesla-jazn'


def test_pl_fancy():
    """Test a string with Polish diacritical characters and fancy characters."""
    o = nikola.utils.slugify(u'Zażółć gęślą jaźń!-123.456', lang='pl')
    assert o == u'zazolc-gesla-jazn-123456'
    assert isinstance(o, nikola.utils.unicode_str)


def test_disarmed():
    """Test disarmed slugify."""
    nikola.utils.USE_SLUGIFY = False
    o = nikola.utils.slugify(u'Zażółć gęślą jaźń!-123.456', lang='pl')
    assert o == u'Zażółć gęślą jaźń!-123.456'
    assert isinstance(o, nikola.utils.unicode_str)
    nikola.utils.USE_SLUGIFY = True


def test_disarmed_weird():
    """Test disarmed slugify with banned characters."""
    nikola.utils.USE_SLUGIFY = False
    o = nikola.utils.slugify(u'Zażółć gęślą jaźń!-123.456 "Hello World"?#H<e>l/l\\o:W\'o\rr*l\td|!\n', lang='pl')
    assert o == u'Zażółć gęślą jaźń!-123.456 -Hello World---H-e-l-l-o-W-o-r-l-d-!-'
    assert isinstance(o, nikola.utils.unicode_str)
    nikola.utils.USE_SLUGIFY = True