mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
RFE #1491485: str/unicode.endswith()/startswith() now accept a tuple as first argument.
This commit is contained in:
parent
932f5afbe8
commit
242508160e
5 changed files with 182 additions and 83 deletions
|
@ -819,6 +819,21 @@ class MixinStrUnicodeUserStringTest:
|
|||
self.checkraises(TypeError, 'hello', 'startswith')
|
||||
self.checkraises(TypeError, 'hello', 'startswith', 42)
|
||||
|
||||
# test tuple arguments
|
||||
self.checkequal(True, 'hello', 'startswith', ('he', 'ha'))
|
||||
self.checkequal(False, 'hello', 'startswith', ('lo', 'llo'))
|
||||
self.checkequal(True, 'hello', 'startswith', ('hellox', 'hello'))
|
||||
self.checkequal(False, 'hello', 'startswith', ())
|
||||
self.checkequal(True, 'helloworld', 'startswith', ('hellowo',
|
||||
'rld', 'lowo'), 3)
|
||||
self.checkequal(False, 'helloworld', 'startswith', ('hellowo', 'ello',
|
||||
'rld'), 3)
|
||||
self.checkequal(True, 'hello', 'startswith', ('lo', 'he'), 0, -1)
|
||||
self.checkequal(False, 'hello', 'startswith', ('he', 'hel'), 0, 1)
|
||||
self.checkequal(True, 'hello', 'startswith', ('he', 'hel'), 0, 2)
|
||||
|
||||
self.checkraises(TypeError, 'hello', 'startswith', (42,))
|
||||
|
||||
def test_endswith(self):
|
||||
self.checkequal(True, 'hello', 'endswith', 'lo')
|
||||
self.checkequal(False, 'hello', 'endswith', 'he')
|
||||
|
@ -853,6 +868,21 @@ class MixinStrUnicodeUserStringTest:
|
|||
self.checkraises(TypeError, 'hello', 'endswith')
|
||||
self.checkraises(TypeError, 'hello', 'endswith', 42)
|
||||
|
||||
# test tuple arguments
|
||||
self.checkequal(False, 'hello', 'endswith', ('he', 'ha'))
|
||||
self.checkequal(True, 'hello', 'endswith', ('lo', 'llo'))
|
||||
self.checkequal(True, 'hello', 'endswith', ('hellox', 'hello'))
|
||||
self.checkequal(False, 'hello', 'endswith', ())
|
||||
self.checkequal(True, 'helloworld', 'endswith', ('hellowo',
|
||||
'rld', 'lowo'), 3)
|
||||
self.checkequal(False, 'helloworld', 'endswith', ('hellowo', 'ello',
|
||||
'rld'), 3, -1)
|
||||
self.checkequal(True, 'hello', 'endswith', ('hell', 'ell'), 0, -1)
|
||||
self.checkequal(False, 'hello', 'endswith', ('he', 'hel'), 0, 1)
|
||||
self.checkequal(True, 'hello', 'endswith', ('he', 'hell'), 0, 4)
|
||||
|
||||
self.checkraises(TypeError, 'hello', 'endswith', (42,))
|
||||
|
||||
def test___contains__(self):
|
||||
self.checkequal(True, '', '__contains__', '') # vereq('' in '', True)
|
||||
self.checkequal(True, 'abc', '__contains__', '') # vereq('' in 'abc', True)
|
||||
|
@ -872,7 +902,7 @@ class MixinStrUnicodeUserStringTest:
|
|||
self.checkequal(u'abc', 'abc', '__getitem__', slice(0, 1000))
|
||||
self.checkequal(u'a', 'abc', '__getitem__', slice(0, 1))
|
||||
self.checkequal(u'', 'abc', '__getitem__', slice(0, 0))
|
||||
# FIXME What about negative indizes? This is handled differently by [] and __getitem__(slice)
|
||||
# FIXME What about negative indices? This is handled differently by [] and __getitem__(slice)
|
||||
|
||||
self.checkraises(TypeError, 'abc', '__getitem__', 'def')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue