Skip to content

gh-73123: Test for keepempty argument to string split #26196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Lib/test/string_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,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):
# without arg
self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit')
Expand Down
Loading