[formatter] implement 'S' format specifier (#3266)

to Sort lists
This commit is contained in:
Mike Fährmann
2022-11-21 21:44:42 +01:00
parent 8a021e4ee4
commit 42481aed59
4 changed files with 40 additions and 1 deletions

View File

@@ -219,6 +219,21 @@ class TestFormatter(unittest.TestCase):
time.timezone = orig_timezone
time.altzone = orig_altzone
def test_sort(self):
self._run_test("{l:S}" , "['a', 'b', 'c']")
self._run_test("{l:Sa}", "['a', 'b', 'c']")
self._run_test("{l:Sd}", "['c', 'b', 'a']")
self._run_test("{l:Sr}", "['c', 'b', 'a']")
self._run_test(
"{a:S}", "[' ', 'E', 'L', 'L', 'O', 'd', 'h', 'l', 'o', 'r', 'w']")
self._run_test(
"{a:S-asc}", # starts with 'S', contains 'a'
"[' ', 'E', 'L', 'L', 'O', 'd', 'h', 'l', 'o', 'r', 'w']")
self._run_test(
"{a:Sort-reverse}", # starts with 'S', contains 'r'
"['w', 'r', 'o', 'l', 'h', 'd', 'O', 'L', 'L', 'E', ' ']")
def test_chain_special(self):
# multiple replacements
self._run_test("{a:Rh/C/RE/e/RL/l/}", "Cello wOrld")
@@ -237,6 +252,9 @@ class TestFormatter(unittest.TestCase):
# parse and format datetime
self._run_test("{ds:D%Y-%m-%dT%H:%M:%S%z/%Y%m%d}", "20100101")
# sort and join
self._run_test("{a:S/J}", " ELLOdhlorw")
def test_separator(self):
orig_separator = formatter._SEPARATOR
try: