[formatter] add 'g' conversion to sluGify a string (#2410)

This commit is contained in:
Mike Fährmann
2022-08-23 21:14:55 +02:00
parent e4cff67aaa
commit 67bad04dda
5 changed files with 36 additions and 1 deletions

View File

@@ -58,6 +58,7 @@ class TestFormatter(unittest.TestCase):
self._run_test("{dt!T}", "1262304000")
self._run_test("{l!j}", '["a", "b", "c"]')
self._run_test("{dt!j}", '"2010-01-01 00:00:00"')
self._run_test("{a!g}", "hello-world")
with self.assertRaises(KeyError):
self._run_test("{a!q}", "hello world")

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2015-2021 Mike Fährmann
# Copyright 2015-2022 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -75,6 +75,23 @@ class TestText(unittest.TestCase):
for value in INVALID:
self.assertEqual(f(value), empty)
def test_slugify(self, f=text.slugify):
self.assertEqual(f("Hello World"), "hello-world")
self.assertEqual(f("-HeLLo---World-"), "hello-world")
self.assertEqual(f("_-H#e:l#l:o+\t+W?o!rl=d-_"), "hello-world")
self.assertEqual(f("_Hello_World_"), "hello_world")
self.assertEqual(f(""), "")
self.assertEqual(f("-"), "")
self.assertEqual(f("--"), "")
self.assertEqual(f(()), "")
self.assertEqual(f([]), "")
self.assertEqual(f({}), "")
self.assertEqual(f(None), "none")
self.assertEqual(f(1), "1")
self.assertEqual(f(2.3), "23")
def test_ensure_http_scheme(self, f=text.ensure_http_scheme):
result = "https://example.org/filename.ext"