summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2022-10-15 18:40:22 (GMT)
committerGitHub <noreply@github.com>2022-10-15 18:40:22 (GMT)
commitb7dd2cad186e44e2b481f4518be62f34c682ea59 (patch)
treee350e11c21257070d19062abd88b5c89946f3aee
parentf4370318d67f1f2f686c1c3a4b217ccc461d31e5 (diff)
downloadcpython-b7dd2cad186e44e2b481f4518be62f34c682ea59.zip
cpython-b7dd2cad186e44e2b481f4518be62f34c682ea59.tar.gz
cpython-b7dd2cad186e44e2b481f4518be62f34c682ea59.tar.bz2
gh-94808: Cover `str.rsplit` for UCS1, UCS2 or UCS4 (#98228)
-rw-r--r--Lib/test/string_tests.py8
-rw-r--r--Lib/test/test_unicode.py8
2 files changed, 14 insertions, 2 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index e998146..709cac7 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -505,6 +505,11 @@ class BaseTest:
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)
@@ -558,6 +563,9 @@ class BaseTest:
# 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 15244cb..05e7e30 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -445,10 +445,10 @@ class UnicodeTest(string_tests.CommonTest,
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 @@ class UnicodeTest(string_tests.CommonTest,
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