[pypy-commit] pypy default: Test and fix for RopeString.find

amauryfa noreply at buildbot.pypy.org
Sat Jun 2 09:15:38 CEST 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r55271:04e2b329ede5
Date: 2012-06-02 09:14 +0200
http://bitbucket.org/pypy/pypy/changeset/04e2b329ede5/

Log:	Test and fix for RopeString.find

diff --git a/pypy/objspace/std/test/test_stringobject.py b/pypy/objspace/std/test/test_stringobject.py
--- a/pypy/objspace/std/test/test_stringobject.py
+++ b/pypy/objspace/std/test/test_stringobject.py
@@ -413,6 +413,9 @@
         assert 'abcdefghiabc'.find('def', 4) == -1
         assert 'abcdef'.find('', 13) == -1
         assert 'abcdefg'.find('def', 5, None) == -1
+        assert 'abcdef'.find('d', 6, 0) == -1
+        assert 'abcdef'.find('d', 3, 3) == -1
+        raises(TypeError, 'abcdef'.find, 'd', 1.0)
 
     def test_index(self):
         from sys import maxint
diff --git a/pypy/rlib/rope.py b/pypy/rlib/rope.py
--- a/pypy/rlib/rope.py
+++ b/pypy/rlib/rope.py
@@ -769,11 +769,11 @@
     len2 = subnode.length()
     if stop > len1 or stop == -1:
         stop = len1
+    if stop - start < 0:
+        return -1
     if len2 == 1:
         return find_int(node, subnode.getint(0), start, stop)
     if len2 == 0:
-        if (stop - start) < 0:
-            return -1
         return start
     if len2 > stop - start:
         return -1


More information about the pypy-commit mailing list