summaryrefslogtreecommitdiff
path: root/Lib/test/string_tests.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-01-02 21:12:58 +0000
committerAntoine Pitrou <solipsis@pitrou.net>2010-01-02 21:12:58 +0000
commit5b7139aab41becad7ad736bd9ff2332960bf67f9 (patch)
tree9d3d3e7da0c0073af1fd2784fa7892d3222f9e88 /Lib/test/string_tests.py
parentd3e323215c6d9f303bf42875f98e365e2ff1734f (diff)
downloadcpython-git-5b7139aab41becad7ad736bd9ff2332960bf67f9.tar.gz
Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
`rindex`, `rsplit` and `rpartition` methods. Patch by Florent Xicluna.
Diffstat (limited to 'Lib/test/string_tests.py')
-rw-r--r--Lib/test/string_tests.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index caff3d4c34..988372dd71 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -230,6 +230,31 @@ class CommonTest(unittest.TestCase):
self.checkraises(TypeError, 'hello', 'rfind')
self.checkraises(TypeError, 'hello', 'rfind', 42)
+ # For a variety of combinations,
+ # verify that str.rfind() matches __contains__
+ # and that the found substring is really at that location
+ charset = ['', 'a', 'b', 'c']
+ digits = 5
+ base = len(charset)
+ teststrings = set()
+ for i in xrange(base ** digits):
+ entry = []
+ for j in xrange(digits):
+ i, m = divmod(i, base)
+ entry.append(charset[m])
+ teststrings.add(''.join(entry))
+ teststrings = list(teststrings)
+ for i in teststrings:
+ i = self.fixtype(i)
+ for j in teststrings:
+ loc = i.rfind(j)
+ r1 = (loc != -1)
+ r2 = j in i
+ if r1 != r2:
+ self.assertEqual(r1, r2)
+ if loc != -1:
+ self.assertEqual(i[loc:loc+len(j)], j)
+
def test_index(self):
self.checkequal(0, 'abcdefghiabc', 'index', '')
self.checkequal(3, 'abcdefghiabc', 'index', 'def')
@@ -686,8 +711,10 @@ class CommonTest(unittest.TestCase):
EQ("bobobXbobob", "bobobobXbobobob", "replace", "bobob", "bob")
EQ("BOBOBOB", "BOBOBOB", "replace", "bob", "bobby")
- ba = buffer('a')
- bb = buffer('b')
+ # Silence Py3k warning
+ with test_support.check_warnings():
+ ba = buffer('a')
+ bb = buffer('b')
EQ("bbc", "abc", "replace", ba, bb)
EQ("aac", "abc", "replace", bb, ba)