Skip to content

Commit

Permalink
pythongh-94808: Cover str.rsplit for UCS1, UCS2 or UCS4 (pythonGH-9…
Browse files Browse the repository at this point in the history
…8228)

(cherry picked from commit b7dd2ca)

Co-authored-by: Nikita Sobolev <[email protected]>
  • Loading branch information
sobolevn authored and miss-islington committed Oct 15, 2022
1 parent 099620b commit 7be0bdd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Lib/test/string_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,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 @@ -522,6 +527,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 @@ -441,10 +441,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'):
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 @@ -454,6 +454,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

0 comments on commit 7be0bdd

Please sign in to comment.