summaryrefslogtreecommitdiff
path: root/Lib/test/string_tests.py
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2003-04-10 22:35:32 +0000
committerNeal Norwitz <nnorwitz@gmail.com>2003-04-10 22:35:32 +0000
commitffe33b7f2416132d2e5b64683dbcc2aaf0596937 (patch)
treeba66fc78e483c14dc34b86a8f079d5b37268f03d /Lib/test/string_tests.py
parent5c16c7b014f4cf975d25f667f6309933415e130d (diff)
downloadcpython-git-ffe33b7f2416132d2e5b64683dbcc2aaf0596937.tar.gz
Attempt to make all the various string *strip methods the same.
* Doc - add doc for when functions were added * UserString * string object methods * string module functions 'chars' is used for the last parameter everywhere. These changes will be backported, since part of the changes have already been made, but they were inconsistent.
Diffstat (limited to 'Lib/test/string_tests.py')
-rw-r--r--Lib/test/string_tests.py55
1 files changed, 27 insertions, 28 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index dcf961d1ff..591b409ae3 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -195,6 +195,33 @@ class CommonTest(unittest.TestCase):
self.checkequal(' hello', ' hello ', 'rstrip')
self.checkequal('hello', 'hello', 'strip')
+ # 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)
+
+ # 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')
+
+ # strip/lstrip/rstrip with unicode arg
+ if test_support.have_unicode:
+ self.checkequal(unicode('hello', 'ascii'), 'xyzzyhelloxyzzy',
+ 'strip', unicode('xyz', 'ascii'))
+ self.checkequal(unicode('helloxyzzy', 'ascii'), 'xyzzyhelloxyzzy',
+ 'lstrip', unicode('xyz', 'ascii'))
+ self.checkequal(unicode('xyzzyhello', 'ascii'), 'xyzzyhelloxyzzy',
+ 'rstrip', unicode('xyz', 'ascii'))
+ self.checkequal(unicode('hello', 'ascii'), 'hello',
+ 'strip', unicode('xyz', 'ascii'))
+
+ self.checkraises(TypeError, 'hello', 'strip', 42, 42)
+ self.checkraises(TypeError, 'hello', 'lstrip', 42, 42)
+ self.checkraises(TypeError, 'hello', 'rstrip', 42, 42)
+
def test_ljust(self):
self.checkequal('abc ', 'abc', 'ljust', 10)
self.checkequal('abc ', 'abc', 'ljust', 6)
@@ -432,34 +459,6 @@ class MixinStrUnicodeUserStringTest:
self.checkraises(TypeError, 'hello', 'endswith')
self.checkraises(TypeError, 'hello', 'endswith', 42)
- def test_strip_args(self):
- # 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)
-
- # 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')
-
- # strip/lstrip/rstrip with unicode arg
- if test_support.have_unicode:
- self.checkequal(unicode('hello', 'ascii'), 'xyzzyhelloxyzzy',
- 'strip', unicode('xyz', 'ascii'))
- self.checkequal(unicode('helloxyzzy', 'ascii'), 'xyzzyhelloxyzzy',
- 'lstrip', unicode('xyz', 'ascii'))
- self.checkequal(unicode('xyzzyhello', 'ascii'), 'xyzzyhelloxyzzy',
- 'rstrip', unicode('xyz', 'ascii'))
- self.checkequal(unicode('hello', 'ascii'), 'hello',
- 'strip', unicode('xyz', 'ascii'))
-
- self.checkraises(TypeError, 'hello', 'strip', 42, 42)
- self.checkraises(TypeError, 'hello', 'lstrip', 42, 42)
- self.checkraises(TypeError, 'hello', 'rstrip', 42, 42)
-
def test___contains__(self):
self.checkequal(True, '', '__contains__', '') # vereq('' in '', True)
self.checkequal(True, 'abc', '__contains__', '') # vereq('' in 'abc', True)