diff options
author | Hye-Shik Chang <hyeshik@gmail.com> | 2003-12-15 18:49:53 (GMT) |
---|---|---|
committer | Hye-Shik Chang <hyeshik@gmail.com> | 2003-12-15 18:49:53 (GMT) |
commit | 3ae811b57d227a220f207869487fd9251e278608 (patch) | |
tree | ccbc4b81578fa69e6bc65df8da4994bf9a4b6e49 /Lib/test | |
parent | dce391cb398f4ce266d98130d10810a6a36617b3 (diff) | |
download | cpython-3ae811b57d227a220f207869487fd9251e278608.zip cpython-3ae811b57d227a220f207869487fd9251e278608.tar.gz cpython-3ae811b57d227a220f207869487fd9251e278608.tar.bz2 |
Add rsplit method for str and unicode builtin types.
SF feature request #801847.
Original patch is written by Sean Reifschneider.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/string_tests.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index 236c577..c3e53ad 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -189,6 +189,26 @@ class CommonTest(unittest.TestCase): self.checkraises(TypeError, 'hello', 'split', 42, 42, 42) + def test_rsplit(self): + self.checkequal(['this', 'is', 'the', 'rsplit', 'function'], + 'this is the rsplit function', 'rsplit') + self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|') + self.checkequal(['a|b', 'c', 'd'], 'a|b|c|d', 'rsplit', '|', 2) + self.checkequal(['a b c', 'd'], 'a b c d', 'rsplit', None, 1) + self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', None, 2) + self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, 3) + self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'rsplit', None, 4) + self.checkequal(['a b c d'], 'a b c d', 'rsplit', None, 0) + self.checkequal(['a, b, c', 'd'], 'a, b, c, d', 'rsplit', ', ', 1) + self.checkequal(['a, b', 'c', 'd'], 'a, b, c, d', 'rsplit', ', ', 2) + self.checkequal(['a', 'b', 'c', 'd'], 'a, b, c, d', 'rsplit', ', ', 3) + self.checkequal(['a', 'b', 'c', 'd'], 'a, b, c, d', 'rsplit', ', ', 4) + self.checkequal(['a, b, c, d'], 'a, b, c, d', 'rsplit', ', ', 0) + self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', None, 2) + self.checkequal(['a\x00b', 'c'], 'a\x00b\x00c', 'rsplit', '\x00', 1) + self.checkequal(['', ''], 'abcd', 'rsplit', 'abcd') + self.checkequal([u'a b', u'c', u'd'], 'a b c d', 'rsplit', u' ', 2) + def test_strip(self): self.checkequal('hello', ' hello ', 'strip') self.checkequal('hello ', ' hello ', 'lstrip') |