[pypy-svn] r59441 - in pypy/trunk/pypy/objspace/std: . test

fijal at codespeak.net fijal at codespeak.net
Mon Oct 27 12:18:34 CET 2008


Author: fijal
Date: Mon Oct 27 12:18:33 2008
New Revision: 59441

Modified:
   pypy/trunk/pypy/objspace/std/stringobject.py
   pypy/trunk/pypy/objspace/std/test/test_stringobject.py
Log:
A bit artificial "error conditions", enforced by cpython's test suite


Modified: pypy/trunk/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/stringobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/stringobject.py	Mon Oct 27 12:18:33 2008
@@ -411,11 +411,15 @@
 
 def str_find__String_String_ANY_ANY(space, w_self, w_sub, w_start, w_end):
     (self, sub, start, end) =  _convert_idx_params(space, w_self, w_sub, w_start, w_end)
+    if space.int_w(w_start) > len(self):
+        return space.wrap(-1)
     res = self.find(sub, start, end)
     return space.wrap(res)
 
 def str_rfind__String_String_ANY_ANY(space, w_self, w_sub, w_start, w_end):
     (self, sub, start, end) =  _convert_idx_params(space, w_self, w_sub, w_start, w_end)
+    if space.int_w(w_start) > len(self):
+        return space.wrap(-1)
     res = self.rfind(sub, start, end)
     return space.wrap(res)
 

Modified: pypy/trunk/pypy/objspace/std/test/test_stringobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_stringobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/test/test_stringobject.py	Mon Oct 27 12:18:33 2008
@@ -445,10 +445,13 @@
         raises(TypeError, 'abcdefghijklmn'.index, 'abc', -10.0, 30)
 
     def test_rfind(self):
+        assert 'abc'.rfind('', 4) == -1
         assert 'abcdefghiabc'.rfind('abc') == 9
         assert 'abcdefghiabc'.rfind('') == 12
         assert 'abcdefghiabc'.rfind('abcd') == 0
         assert 'abcdefghiabc'.rfind('abcz') == -1
+        assert 'abc'.rfind('', 0) == 3
+        assert 'abc'.rfind('', 3) == 3
 
     def test_rindex(self):
         from sys import maxint



More information about the Pypy-commit mailing list