summaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
authorVal Neekman <val@neekware.com>2017-04-01 12:47:34 -0400
committerVal Neekman <val@neekware.com>2017-04-01 12:47:34 -0400
commitb3b38b1fec893326f86363b9821aec6604a11925 (patch)
tree48411b2193ecbe11b4b31eff09d1a9e3886b919a /test.py
parentcf90eeb80c0692480db8a31a159e1dfd24e1c2b8 (diff)
parent750c737b37a7261ef551f9ab013dfb0b1b3eb29a (diff)
downloadpython-slugify-1.2.2.tar.gz
add regex_pattern and support for py 3.61.2.2
Diffstat (limited to 'test.py')
-rw-r--r--test.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/test.py b/test.py
index 768fcb9..6730756 100644
--- a/test.py
+++ b/test.py
@@ -167,6 +167,36 @@ class TestSlugification(unittest.TestCase):
r = slugify(txt)
self.assertEqual(r, '1000-reasons-you-are-1')
+ def test_regex_pattern_keep_underscore(self):
+ txt = "___This is a test___"
+ regex_pattern = r'[^-a-z0-9_]+'
+ r = slugify(txt, regex_pattern=regex_pattern)
+ self.assertEqual(r, "___this-is-a-test___")
+
+ def test_regex_pattern_keep_underscore_with_underscore_as_separator(self):
+ """
+ The regex_pattern turns the power to the caller.
+ Hence the caller must ensure that a custom separator doesn't clash
+ with the regex_pattern.
+ """
+ txt = "___This is a test___"
+ regex_pattern = r'[^-a-z0-9_]+'
+ r = slugify(txt, separator='_', regex_pattern=regex_pattern)
+ self.assertNotEqual(r, "_this_is_a_test_")
+
+
+class TestUtils(unittest.TestCase):
+
+ def test_smart_truncate_no_max_length(self):
+ txt = '1,000 reasons you are #1'
+ r = smart_truncate(txt)
+ self.assertEqual(r, txt)
+
+ def test_smart_truncate_no_seperator(self):
+ txt = '1,000 reasons you are #1'
+ r = smart_truncate(txt, max_length=100, separator='_')
+ self.assertEqual(r, txt)
+
class TestUtils(unittest.TestCase):