summaryrefslogtreecommitdiff
path: root/Lib/test/string_tests.py
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-04-10 08:45:26 +0000
committerMartin Panter <vadmium+py@gmail.com>2016-04-10 08:45:26 +0000
commit0d0db6cc1e3ef5c32f6bc9f4e47be2428c43423f (patch)
tree0e40c7b923db9090a9bb847f9bab299e2aaec305 /Lib/test/string_tests.py
parentd979b2cfcf4047b8f9b46e169cfa071e80e30d71 (diff)
downloadcpython-git-0d0db6cc1e3ef5c32f6bc9f4e47be2428c43423f.tar.gz
Issue #26712: Unify (r)split, (l/r)strip tests into string_tests
This eliminates a few redundant test cases.
Diffstat (limited to 'Lib/test/string_tests.py')
-rw-r--r--Lib/test/string_tests.py36
1 files changed, 31 insertions, 5 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index b21fa81ef3..7d30e9e596 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -368,6 +368,8 @@ class BaseTest:
sys.maxsize-2)
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(['abcd'], 'abcd', 'split', '|')
+ self.checkequal([''], '', 'split', '|')
self.checkequal(['endcase ', ''], 'endcase |', 'split', '|')
self.checkequal(['', ' startcase'], '| startcase', 'split', '|')
self.checkequal(['', 'bothcase', ''], '|bothcase|', 'split', '|')
@@ -435,6 +437,8 @@ class BaseTest:
sys.maxsize-100)
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(['abcd'], 'abcd', 'rsplit', '|')
+ self.checkequal([''], '', 'rsplit', '|')
self.checkequal(['', ' begincase'], '| begincase', 'rsplit', '|')
self.checkequal(['endcase ', ''], 'endcase |', 'rsplit', '|')
self.checkequal(['', 'bothcase', ''], '|bothcase|', 'rsplit', '|')
@@ -714,16 +718,21 @@ class BaseTest:
self.checkequal(['a'], ' a ', 'split')
self.checkequal(['a', 'b'], ' a b ', 'split')
self.checkequal(['a', 'b '], ' a b ', 'split', None, 1)
+ self.checkequal(['a b c '], ' a b c ', 'split', None, 0)
self.checkequal(['a', 'b c '], ' a b c ', 'split', None, 1)
self.checkequal(['a', 'b', 'c '], ' a b c ', 'split', None, 2)
+ self.checkequal(['a', 'b', 'c'], ' a b c ', 'split', None, 3)
self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'split')
aaa = ' a '*20
self.checkequal(['a']*20, aaa, 'split')
self.checkequal(['a'] + [aaa[4:]], aaa, 'split', None, 1)
self.checkequal(['a']*19 + ['a '], aaa, 'split', None, 19)
- # mixed use of str and unicode
- self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', ' ', 2)
+ for b in ('arf\tbarf', 'arf\nbarf', 'arf\rbarf',
+ 'arf\fbarf', 'arf\vbarf'):
+ self.checkequal(['arf', 'barf'], b, 'split')
+ self.checkequal(['arf', 'barf'], b, 'split', None)
+ self.checkequal(['arf', 'barf'], b, 'split', None, 2)
def test_additional_rsplit(self):
self.checkequal(['this', 'is', 'the', 'rsplit', 'function'],
@@ -745,36 +754,53 @@ class BaseTest:
self.checkequal(['a'], ' a ', 'rsplit')
self.checkequal(['a', 'b'], ' a b ', 'rsplit')
self.checkequal([' a', 'b'], ' a b ', 'rsplit', None, 1)
+ self.checkequal([' a b c'], ' a b c ', 'rsplit',
+ None, 0)
self.checkequal([' a b','c'], ' a b c ', 'rsplit',
None, 1)
self.checkequal([' a', 'b', 'c'], ' a b c ', 'rsplit',
None, 2)
+ self.checkequal(['a', 'b', 'c'], ' a b c ', 'rsplit',
+ None, 3)
self.checkequal(['a', 'b'], '\n\ta \t\r b \v ', 'rsplit', None, 88)
aaa = ' a '*20
self.checkequal(['a']*20, aaa, 'rsplit')
self.checkequal([aaa[:-4]] + ['a'], aaa, 'rsplit', None, 1)
self.checkequal([' a a'] + ['a']*18, aaa, 'rsplit', None, 18)
- # mixed use of str and unicode
- self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', ' ', 2)
+ for b in ('arf\tbarf', 'arf\nbarf', 'arf\rbarf',
+ 'arf\fbarf', 'arf\vbarf'):
+ self.checkequal(['arf', 'barf'], b, 'rsplit')
+ self.checkequal(['arf', 'barf'], b, 'rsplit', None)
+ self.checkequal(['arf', 'barf'], b, 'rsplit', None, 2)
- def test_strip(self):
+ def test_strip_whitespace(self):
self.checkequal('hello', ' hello ', 'strip')
self.checkequal('hello ', ' hello ', 'lstrip')
self.checkequal(' hello', ' hello ', 'rstrip')
self.checkequal('hello', 'hello', 'strip')
+ b = ' \t\n\r\f\vabc \t\n\r\f\v'
+ self.checkequal('abc', b, 'strip')
+ self.checkequal('abc \t\n\r\f\v', b, 'lstrip')
+ self.checkequal(' \t\n\r\f\vabc', b, 'rstrip')
+
# strip/lstrip/rstrip with None arg
self.checkequal('hello', ' hello ', 'strip', None)
self.checkequal('hello ', ' hello ', 'lstrip', None)
self.checkequal(' hello', ' hello ', 'rstrip', None)
self.checkequal('hello', 'hello', 'strip', None)
+ def test_strip(self):
# strip/lstrip/rstrip with str arg
self.checkequal('hello', 'xyzzyhelloxyzzy', 'strip', 'xyz')
self.checkequal('helloxyzzy', 'xyzzyhelloxyzzy', 'lstrip', 'xyz')
self.checkequal('xyzzyhello', 'xyzzyhelloxyzzy', 'rstrip', 'xyz')
self.checkequal('hello', 'hello', 'strip', 'xyz')
+ self.checkequal('', 'mississippi', 'strip', 'mississippi')
+
+ # only trim the start and end; does not strip internal characters
+ self.checkequal('mississipp', 'mississippi', 'strip', 'i')
self.checkraises(TypeError, 'hello', 'strip', 42, 42)
self.checkraises(TypeError, 'hello', 'lstrip', 42, 42)