summaryrefslogtreecommitdiffstats
path: root/Lib/test/string_tests.py
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2002-06-14 00:50:42 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2002-06-14 00:50:42 (GMT)
commit1f68fc7fa5048e0576ff26436012765f4a8fa3d4 (patch)
tree2a6269c89b5d90689c29a3aa94f80db58791d1f0 /Lib/test/string_tests.py
parent585775bf118ea8c3450ceaf1fa849140eabf8bd7 (diff)
downloadcpython-1f68fc7fa5048e0576ff26436012765f4a8fa3d4.zip
cpython-1f68fc7fa5048e0576ff26436012765f4a8fa3d4.tar.gz
cpython-1f68fc7fa5048e0576ff26436012765f4a8fa3d4.tar.bz2
SF bug # 493951 string.{starts,ends}with vs slices
Handle negative indices similar to slices.
Diffstat (limited to 'Lib/test/string_tests.py')
-rw-r--r--Lib/test/string_tests.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index 075e1c9..b645354 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -223,6 +223,18 @@ def run_method_tests(test):
test('startswith', 'helloworld', 1, 'lowo', 3, 7)
test('startswith', 'helloworld', 0, 'lowo', 3, 6)
+ # test negative indices in startswith
+ test('startswith', 'hello', 1, 'he', 0, -1)
+ test('startswith', 'hello', 1, 'he', -53, -1)
+ test('startswith', 'hello', 0, 'hello', 0, -1)
+ test('startswith', 'hello', 0, 'hello world', -1, -10)
+ test('startswith', 'hello', 0, 'ello', -5)
+ test('startswith', 'hello', 1, 'ello', -4)
+ test('startswith', 'hello', 0, 'o', -2)
+ test('startswith', 'hello', 1, 'o', -1)
+ test('startswith', 'hello', 1, '', -3, -3)
+ test('startswith', 'hello', 0, 'lo', -9)
+
test('endswith', 'hello', 1, 'lo')
test('endswith', 'hello', 0, 'he')
test('endswith', 'hello', 1, '')
@@ -238,6 +250,21 @@ def run_method_tests(test):
test('endswith', 'ab', 0, 'ab', 0, 1)
test('endswith', 'ab', 0, 'ab', 0, 0)
+ # test negative indices in endswith
+ test('endswith', 'hello', 1, 'lo', -2)
+ test('endswith', 'hello', 0, 'he', -2)
+ test('endswith', 'hello', 1, '', -3, -3)
+ test('endswith', 'hello', 0, 'hello world', -10, -2)
+ test('endswith', 'helloworld', 0, 'worl', -6)
+ test('endswith', 'helloworld', 1, 'worl', -5, -1)
+ test('endswith', 'helloworld', 1, 'worl', -5, 9)
+ test('endswith', 'helloworld', 1, 'world', -7, 12)
+ test('endswith', 'helloworld', 1, 'lowo', -99, -3)
+ test('endswith', 'helloworld', 1, 'lowo', -8, -3)
+ test('endswith', 'helloworld', 1, 'lowo', -7, -3)
+ test('endswith', 'helloworld', 0, 'lowo', 3, -4)
+ test('endswith', 'helloworld', 0, 'lowo', -8, -2)
+
test('zfill', '123', '123', 2)
test('zfill', '123', '123', 3)
test('zfill', '123', '0123', 4)