From f6c12afef99e8789a04ce03e5a9ce22ea0b0627d Mon Sep 17 00:00:00 2001 From: Catherine Devlin Date: Mon, 17 May 2021 14:47:47 -0400 Subject: [PATCH] Test for `keepempty` argument to string split Enforcing suggestion at https://bugs.python.org/msg282923 in https://bugs.python.org/issue28937 As per https://bugs.python.org/issue28937#msg338422 Using `keepempty` rather than `keep_empty` or `keep` (despite annoying length) for consistency with existing `keepends` argument --- Lib/test/string_tests.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index 840d7bb7550f71..9eff99ba70ad97 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -465,6 +465,22 @@ def test_split(self): self.checkraises(ValueError, 'hello', 'split', '') self.checkraises(ValueError, 'hello', 'split', '', 0) + # without args, any whitespace is a separator + self.checkequal(['a', 'b', 'c', 'd', 'e'], 'a b\tc\nd \n e ', 'split') + + # with sep=None, any whitespace is a separator + self.checkequal(['a', 'b', 'c', 'd', 'e'], 'a b\tc\nd \n e ', 'split', sep=None) + + # Without an explicit `sep`, or sep=None, empty strings are pruned from result + self.checkequal([], '', 'split') + self.checkequal([], '', 'split', sep=None) + + # With an explicit, non-None `sep`, empty strings are not pruned from result + self.checkequal([''], '', 'split', sep=',') + + # keepempty=False to remove empty strings from result + self.checkequal([], '', 'split', sep=',', keepempty=False) + def test_rsplit(self): # by a char self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|')