]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-94808: Cover `str.rsplit` for UCS1, UCS2 or UCS4 (#98228)
authorNikita Sobolev <mail@sobolevn.me>
Sat, 15 Oct 2022 18:40:22 +0000 (21:40 +0300)
committerGitHub <noreply@github.com>
Sat, 15 Oct 2022 18:40:22 +0000 (11:40 -0700)
Lib/test/string_tests.py
Lib/test/test_unicode.py

index e998146c190df444a2aecb5cf094153b522b96af..709cac7a27a4497f4edc560a963c3227993c5a23 100644 (file)
@@ -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'],
index 15244cb949e3db29c6170536f0f35f2c109bdd0e..05e7e30d639a296461503dde10afd65655692333 100644 (file)
@@ -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