|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +u"""Test slugify.""" |
| 4 | + |
| 5 | +from __future__ import unicode_literals |
| 6 | +import nikola.utils |
| 7 | + |
| 8 | + |
| 9 | +def test_ascii(): |
| 10 | + """Test an ASCII-only string.""" |
| 11 | + o = nikola.utils.slugify(u'hello') |
| 12 | + assert o == u'hello' |
| 13 | + assert isinstance(o, nikola.utils.unicode_str) |
| 14 | + |
| 15 | + |
| 16 | +def test_ascii_dash(): |
| 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' |
| 27 | + assert isinstance(o, nikola.utils.unicode_str) |
| 28 | + |
| 29 | + |
| 30 | +def test_pl(): |
| 31 | + """Test a string with Polish diacritical characters.""" |
| 32 | + o = nikola.utils.slugify(u'zażółćgęśląjaźń') |
| 33 | + assert o == u'zazolcgeslajazn' |
| 34 | + assert isinstance(o, nikola.utils.unicode_str) |
| 35 | + |
| 36 | + |
| 37 | +def test_pl_dash(): |
| 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' |
| 47 | + assert isinstance(o, nikola.utils.unicode_str) |
| 48 | + |
| 49 | + |
| 50 | +def test_disarmed(): |
| 51 | + """Test disarmed slugify.""" |
| 52 | + nikola.utils.USE_SLUGIFY = False |
| 53 | + o = nikola.utils.slugify(u'Zażółć gęślą jaźń!-123.456') |
| 54 | + assert o == u'Zażółć gęślą jaźń!-123.456' |
| 55 | + assert isinstance(o, nikola.utils.unicode_str) |
| 56 | + nikola.utils.USE_SLUGIFY = True |
| 57 | + |
| 58 | + |
| 59 | +def test_disarmed_weird(): |
| 60 | + """Test disarmed slugify with banned characters.""" |
| 61 | + nikola.utils.USE_SLUGIFY = False |
| 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-!-' |
| 64 | + assert isinstance(o, nikola.utils.unicode_str) |
| 65 | + nikola.utils.USE_SLUGIFY = True |
0 commit comments