]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-94808: Cover `str.rsplit` for UCS1, UCS2 or UCS4 (GH-98228) (#98291)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 20 Oct 2022 00:53:50 +0000 (17:53 -0700)
committerGitHub <noreply@github.com>
Thu, 20 Oct 2022 00:53:50 +0000 (17:53 -0700)
gh-94808: Cover `str.rsplit` for UCS1, UCS2 or UCS4 (GH-98228)
(cherry picked from commit b7dd2cad186e44e2b481f4518be62f34c682ea59)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Lib/test/string_tests.py
Lib/test/test_unicode.py

index 0d4c7ecf4a04f2bc0c09b49dd86c9220ac668740..d69edd7bf458da8bc5f2fc9b71f67ba44d220b15 100644 (file)
@@ -469,6 +469,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)
@@ -522,6 +527,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'],
index 9b0e4b230506a8b3f1cc063454879a05b306789f..60e5b1902cf698fa98a002ed9f63a6c9b4cd139c 100644 (file)
@@ -441,10 +441,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],
@@ -454,6 +454,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