mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +00:00
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.
This commit is contained in:
parent
5c16c7b014
commit
ffe33b7f24
6 changed files with 64 additions and 58 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue