Skip to content
Permalink
Browse files

Better slugify tests; remove dupliate banned character

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 11, 2015
1 parent 50f92ad commit 6de860b2d72d405c3b152d1501e283340bde3407
Showing with 42 additions and 13 deletions.
  1. +1 −1 nikola/utils.py
  2. +41 −12 tests/test_slugify.py
@@ -740,7 +740,7 @@ def slugify(value, force=False):
# We still replace some characters, though. In particular, we need
# to replace ? and #, which should not appear in URLs, and some
# Windows-unsafe characters. This list might be even longer.
rc = '/\\?#"\'\r\n\t*:<>|"'
rc = '/\\?#"\'\r\n\t*:<>|'

for c in rc:
value = value.replace(c, '-')
@@ -1,36 +1,65 @@
# -*- coding: utf-8 -*-

u"""Test slugify."""

from __future__ import unicode_literals
import nikola.utils


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


def test_ascii_dash():
o = nikola.utils.slugify(u'abc-def')
assert o == u'abc-def'
"""Test an ASCII string, with dashes."""
o = nikola.utils.slugify(u'hello-world')
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')
assert o == u'the-quick-brown-fox-jumps-over-the-lazy-dog-123456'
assert isinstance(o, nikola.utils.unicode_str)


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


def test_pl_dash():
o = nikola.utils.slugify(u'ąbć-def')
assert o == u'abc-def'
"""Test a string with Polish diacritical characters and dashes."""
o = nikola.utils.slugify(u'zażółć-gęślą-jaźń')
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')
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'ąbć-def')
assert o == u'ąbć-def'
o = nikola.utils.slugify(u'Zażółć gęślą jaźń!-123.456')
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'ąbć-def "Hello World"?#H<e>l/l\\o:W\'o\rr*l\td|!\n')
assert o == u'ąbć-def -Hello World---H-e-l-l-o-W-o-r-l-d-!-'
o = nikola.utils.slugify(u'Zażółć gęślą jaźń!-123.456 "Hello World"?#H<e>l/l\\o:W\'o\rr*l\td|!\n')
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

0 comments on commit 6de860b

Please sign in to comment.
You can’t perform that action at this time.