Skip to content
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

gh-94808: Cover str.rsplit for UCS1, UCS2 or UCS4 #98228

Merged
merged 3 commits into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions Lib/test/string_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ def test_split(self):
self.checkraises(ValueError, 'hello', 'split', '', 0)

def test_rsplit(self):
# without arg
self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit')
self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit')
self.checkequal([], '', 'rsplit')

# by a char
self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|')
self.checkequal(['a|b|c', 'd'], 'a|b|c|d', 'rsplit', '|', 1)
Expand Down Expand Up @@ -558,6 +563,9 @@ def test_rsplit(self):

# with keyword args
self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', sep='|')
self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', sep=None)
self.checkequal(['a b c', 'd'],
'a b c d', 'rsplit', sep=None, maxsplit=1)
self.checkequal(['a|b|c', 'd'],
'a|b|c|d', 'rsplit', '|', maxsplit=1)
self.checkequal(['a|b|c', 'd'],
Expand Down
8 changes: 6 additions & 2 deletions Lib/test/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,10 @@ def test_split(self):
def test_rsplit(self):
string_tests.CommonTest.test_rsplit(self)
# test mixed kinds
for left, right in ('ba', '\u0101\u0100', '\U00010301\U00010300'):
for left, right in ('ba', 'юё', '\u0101\u0100', '\U00010301\U00010300'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cover all of the UCS-1, UCS-2, and UCS-4 branches? Might be worth commenting on which versions are covered by which characters.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other places don't have comments about it, so I didn't bother adding one as well.
I believe that this does cover all unicode kinds: ba', 'юё' are UCS-1, \u0101\u0100 is UCS-2 and \U00010301\U00010300 is UCS-4

left *= 9
right *= 9
for delim in ('c', '\u0102', '\U00010302'):
for delim in ('c', 'ы', '\u0102', '\U00010302'):
self.checkequal([left + right],
left + right, 'rsplit', delim)
self.checkequal([left, right],
Expand All @@ -458,6 +458,10 @@ def test_rsplit(self):
self.checkequal([left, right],
left + delim * 2 + right, 'rsplit', delim *2)

# Check `None` as well:
self.checkequal([left + right],
left + right, 'rsplit', None)

def test_partition(self):
string_tests.MixinStrUnicodeUserStringTest.test_partition(self)
# test mixed kinds
Expand Down