From 523e5bb3a4fb7b09a270892af69df3bb07fff533 Mon Sep 17 00:00:00 2001
From: sobolevn
Date: Thu, 13 Oct 2022 01:45:52 +0300
Subject: [PATCH 1/2] gh-94808: Cover `str.rsplit` for UCS1, UCS2 or UCS4
---
Lib/test/string_tests.py | 7 +++++++
Lib/test/test_unicode.py | 8 ++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index e998146c190df44..35cb0fb681d4405 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -505,6 +505,10 @@ 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')
+
# 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)
@@ -558,6 +562,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'],
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 15244cb949e3db2..05e7e30d639a296 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -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'):
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],
@@ -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
From 06f86c91f7e8d849676cab681f3cc71cc17cf049 Mon Sep 17 00:00:00 2001
From: sobolevn
Date: Thu, 13 Oct 2022 02:00:44 +0300
Subject: [PATCH 2/2] Add more cases
---
Lib/test/string_tests.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index 35cb0fb681d4405..709cac7a27a4497 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -507,7 +507,8 @@ def test_split(self):
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(['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', '|')