summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorHye-Shik Chang <hyeshik@gmail.com>2004-01-05 00:29:51 (GMT)
committerHye-Shik Chang <hyeshik@gmail.com>2004-01-05 00:29:51 (GMT)
commit75c00efcc79d8207242685ddbd499d5af892bfd1 (patch)
tree4b91c2c7ef9158f1959dec8fb7b6f73e18505330 /Lib/test
parentcb2117a83cf09dcccb7882f8b8210f74b8206ae0 (diff)
downloadcpython-75c00efcc79d8207242685ddbd499d5af892bfd1.zip
cpython-75c00efcc79d8207242685ddbd499d5af892bfd1.tar.gz
cpython-75c00efcc79d8207242685ddbd499d5af892bfd1.tar.bz2
[SF #866875] Add a specialized routine for one character
separaters on str.split() and str.rsplit().
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/string_tests.py69
1 files changed, 55 insertions, 14 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index eafc89a..860c1f2 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -175,41 +175,82 @@ class CommonTest(unittest.TestCase):
def test_split(self):
self.checkequal(['this', 'is', 'the', 'split', 'function'],
'this is the split function', 'split')
- self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|')
- self.checkequal(['a', 'b', 'c|d'], 'a|b|c|d', 'split', '|', 2)
+
+ # by whitespace
+ self.checkequal(['a', 'b', 'c', 'd'], 'a b c d ', 'split')
self.checkequal(['a', 'b c d'], 'a b c d', 'split', None, 1)
self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', None, 2)
self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, 3)
self.checkequal(['a', 'b', 'c', 'd'], 'a b c d', 'split', None, 4)
self.checkequal(['a b c d'], 'a b c d', 'split', None, 0)
self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', None, 2)
- self.checkequal(['a', 'b', 'c', 'd'], 'a b c d ', 'split')
+
+ # by a char
+ self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|')
+ self.checkequal(['a', 'b|c|d'], 'a|b|c|d', 'split', '|', 1)
+ self.checkequal(['a', 'b', 'c|d'], 'a|b|c|d', 'split', '|', 2)
+ self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|', 3)
+ self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|', 4)
+ self.checkequal(['a|b|c|d'], 'a|b|c|d', 'split', '|', 0)
+ self.checkequal(['a', '', 'b||c||d'], 'a||b||c||d', 'split', '|', 2)
+ self.checkequal(['endcase ', ''], 'endcase |', 'split', '|')
+ self.checkequal(['a', '', 'b\x00c\x00d'], 'a\x00\x00b\x00c\x00d', 'split', '\x00', 2)
+
+ # by string
self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//')
+ self.checkequal(['a', 'b//c//d'], 'a//b//c//d', 'split', '//', 1)
+ self.checkequal(['a', 'b', 'c//d'], 'a//b//c//d', 'split', '//', 2)
+ self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//', 3)
+ self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'split', '//', 4)
+ self.checkequal(['a//b//c//d'], 'a//b//c//d', 'split', '//', 0)
+ self.checkequal(['a', '', 'b////c////d'], 'a////b////c////d', 'split', '//', 2)
self.checkequal(['endcase ', ''], 'endcase test', 'split', 'test')
+ # mixed use of str and unicode
+ self.checkequal([u'a', u'b', u'c d'], 'a b c d', 'split', u' ', 2)
+
+ # argument type
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)
+
+ # by whitespace
+ self.checkequal(['a', 'b', 'c', 'd'], 'a b c d ', 'rsplit')
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')
+
+ # 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)
+ 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', '|', 2)
+ self.checkequal(['', ' begincase'], '| begincase', 'rsplit', '|')
+ self.checkequal(['a\x00\x00b', 'c', 'd'], 'a\x00\x00b\x00c\x00d', 'rsplit', '\x00', 2)
+
+ # by string
+ self.checkequal(['a', 'b', 'c', 'd'], 'a//b//c//d', 'rsplit', '//')
+ 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', '//', 2)
+ self.checkequal(['', ' begincase'], 'test begincase', 'rsplit', 'test')
+
+ # mixed use of str and unicode
self.checkequal([u'a b', u'c', u'd'], 'a b c d', 'rsplit', u' ', 2)
- self.checkequal(['', ' endcase'], '| endcase', 'rsplit', '|')
- self.checkequal(['', ' endcase'], 'test endcase', 'rsplit', 'test')
+
+ # argument type
+ self.checkraises(TypeError, 'hello', 'rsplit', 42, 42, 42)
def test_strip(self):
self.checkequal('hello', ' hello ', 'strip')