Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df4aaff

Browse files
[3.11] gh-94808: Cover str.rsplit for UCS1, UCS2 or UCS4 (GH-98228) (#98291)
gh-94808: Cover `str.rsplit` for UCS1, UCS2 or UCS4 (GH-98228) (cherry picked from commit b7dd2ca) Co-authored-by: Nikita Sobolev <[email protected]>
1 parent 0b71dad commit df4aaff

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Lib/test/string_tests.py

+8
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,11 @@ def test_split(self):
469469
self.checkraises(ValueError, 'hello', 'split', '', 0)
470470

471471
def test_rsplit(self):
472+
# without arg
473+
self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit')
474+
self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit')
475+
self.checkequal([], '', 'rsplit')
476+
472477
# by a char
473478
self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|')
474479
self.checkequal(['a|b|c', 'd'], 'a|b|c|d', 'rsplit', '|', 1)
@@ -522,6 +527,9 @@ def test_rsplit(self):
522527

523528
# with keyword args
524529
self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', sep='|')
530+
self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', sep=None)
531+
self.checkequal(['a b c', 'd'],
532+
'a b c d', 'rsplit', sep=None, maxsplit=1)
525533
self.checkequal(['a|b|c', 'd'],
526534
'a|b|c|d', 'rsplit', '|', maxsplit=1)
527535
self.checkequal(['a|b|c', 'd'],

Lib/test/test_unicode.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,10 @@ def test_split(self):
441441
def test_rsplit(self):
442442
string_tests.CommonTest.test_rsplit(self)
443443
# test mixed kinds
444-
for left, right in ('ba', '\u0101\u0100', '\U00010301\U00010300'):
444+
for left, right in ('ba', 'юё', '\u0101\u0100', '\U00010301\U00010300'):
445445
left *= 9
446446
right *= 9
447-
for delim in ('c', '\u0102', '\U00010302'):
447+
for delim in ('c', 'ы', '\u0102', '\U00010302'):
448448
self.checkequal([left + right],
449449
left + right, 'rsplit', delim)
450450
self.checkequal([left, right],
@@ -454,6 +454,10 @@ def test_rsplit(self):
454454
self.checkequal([left, right],
455455
left + delim * 2 + right, 'rsplit', delim *2)
456456

457+
# Check `None` as well:
458+
self.checkequal([left + right],
459+
left + right, 'rsplit', None)
460+
457461
def test_partition(self):
458462
string_tests.MixinStrUnicodeUserStringTest.test_partition(self)
459463
# test mixed kinds

0 commit comments

Comments
 (0)