|
1 | 1 | # -*- coding: utf-8 -*-
|
| 2 | + |
| 3 | +u"""Test slugify.""" |
| 4 | + |
| 5 | +from __future__ import unicode_literals |
2 | 6 | import nikola.utils
|
3 | 7 |
|
| 8 | + |
4 | 9 | def test_ascii():
|
5 |
| - o = nikola.utils.slugify(u'abcdef') |
6 |
| - assert o == u'abcdef' |
| 10 | + """Test an ASCII-only string.""" |
| 11 | + o = nikola.utils.slugify(u'hello') |
| 12 | + assert o == u'hello' |
7 | 13 | assert isinstance(o, nikola.utils.unicode_str)
|
8 | 14 |
|
| 15 | + |
9 | 16 | def test_ascii_dash():
|
10 |
| - o = nikola.utils.slugify(u'abc-def') |
11 |
| - assert o == u'abc-def' |
| 17 | + """Test an ASCII string, with dashes.""" |
| 18 | + o = nikola.utils.slugify(u'hello-world') |
| 19 | + assert o == u'hello-world' |
| 20 | + assert isinstance(o, nikola.utils.unicode_str) |
| 21 | + |
| 22 | + |
| 23 | +def test_ascii_fancy(): |
| 24 | + """Test an ASCII string, with fancy characters.""" |
| 25 | + o = nikola.utils.slugify(u'The quick brown fox jumps over the lazy dog!-123.456') |
| 26 | + assert o == u'the-quick-brown-fox-jumps-over-the-lazy-dog-123456' |
12 | 27 | assert isinstance(o, nikola.utils.unicode_str)
|
13 | 28 |
|
| 29 | + |
14 | 30 | def test_pl():
|
15 |
| - o = nikola.utils.slugify(u'ąbćdef') |
16 |
| - assert o == u'abcdef' |
| 31 | + """Test a string with Polish diacritical characters.""" |
| 32 | + o = nikola.utils.slugify(u'zażółćgęśląjaźń') |
| 33 | + assert o == u'zazolcgeslajazn' |
17 | 34 | assert isinstance(o, nikola.utils.unicode_str)
|
18 | 35 |
|
| 36 | + |
19 | 37 | def test_pl_dash():
|
20 |
| - o = nikola.utils.slugify(u'ąbć-def') |
21 |
| - assert o == u'abc-def' |
| 38 | + """Test a string with Polish diacritical characters and dashes.""" |
| 39 | + o = nikola.utils.slugify(u'zażółć-gęślą-jaźń') |
| 40 | + assert o == u'zazolc-gesla-jazn' |
| 41 | + |
| 42 | + |
| 43 | +def test_pl_fancy(): |
| 44 | + """Test a string with Polish diacritical characters and fancy characters.""" |
| 45 | + o = nikola.utils.slugify(u'Zażółć gęślą jaźń!-123.456') |
| 46 | + assert o == u'zazolc-gesla-jazn-123456' |
22 | 47 | assert isinstance(o, nikola.utils.unicode_str)
|
23 | 48 |
|
| 49 | + |
24 | 50 | def test_disarmed():
|
| 51 | + """Test disarmed slugify.""" |
25 | 52 | nikola.utils.USE_SLUGIFY = False
|
26 |
| - o = nikola.utils.slugify(u'ąbć-def') |
27 |
| - assert o == u'ąbć-def' |
| 53 | + o = nikola.utils.slugify(u'Zażółć gęślą jaźń!-123.456') |
| 54 | + assert o == u'Zażółć gęślą jaźń!-123.456' |
28 | 55 | assert isinstance(o, nikola.utils.unicode_str)
|
29 | 56 | nikola.utils.USE_SLUGIFY = True
|
30 | 57 |
|
| 58 | + |
31 | 59 | def test_disarmed_weird():
|
| 60 | + """Test disarmed slugify with banned characters.""" |
32 | 61 | nikola.utils.USE_SLUGIFY = False
|
33 |
| - o = nikola.utils.slugify(u'ąbć-def "Hello World"?#H<e>l/l\\o:W\'o\rr*l\td|!\n') |
34 |
| - assert o == u'ąbć-def -Hello World---H-e-l-l-o-W-o-r-l-d-!-' |
| 62 | + o = nikola.utils.slugify(u'Zażółć gęślą jaźń!-123.456 "Hello World"?#H<e>l/l\\o:W\'o\rr*l\td|!\n') |
| 63 | + assert o == u'Zażółć gęślą jaźń!-123.456 -Hello World---H-e-l-l-o-W-o-r-l-d-!-' |
35 | 64 | assert isinstance(o, nikola.utils.unicode_str)
|
36 | 65 | nikola.utils.USE_SLUGIFY = True
|
0 commit comments