[pypy-svn] r55649 - in pypy/dist/pypy/rpython: lltypesystem ootypesystem test

arigo at codespeak.net arigo at codespeak.net
Sat Jun 7 13:01:22 CEST 2008


Author: arigo
Date: Sat Jun  7 13:01:20 2008
New Revision: 55649

Modified:
   pypy/dist/pypy/rpython/lltypesystem/rstr.py
   pypy/dist/pypy/rpython/ootypesystem/ootype.py
   pypy/dist/pypy/rpython/test/test_rstr.py
Log:
* Fix failures in test_runicode (test_(r)find_empty_string)
* Improve the tests by hard-coding the expected results instead
  of relying on CPython's changing behavior
* Typo in a test, meaning that rfind() was not really tested!
* Fix bug in rfind() found by really testing it
* Fix ootype to work around CPython 2.4 unicode.(r)find corner
  case bugs.


Modified: pypy/dist/pypy/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rstr.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rstr.py	Sat Jun  7 13:01:20 2008
@@ -514,6 +514,8 @@
         if end > len(s1.chars):
             end = len(s1.chars)
         if len2 == 0:
+            if (end-start) < 0:
+                return -1
             return end
         # Construct the array of possible restarting positions
         T = malloc( SIGNED_ARRAY, len2 )

Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py	Sat Jun  7 13:01:20 2008
@@ -1238,10 +1238,14 @@
 
     def ll_find(self, s, start, end):
         # NOT_RPYTHON
+        if start > len(self._str):  # workaround to cope with corner case
+            return -1               # bugs in CPython 2.4 unicode.find('')
         return self._str.find(s._str, start, end)
 
     def ll_rfind(self, s, start, end):
         # NOT_RPYTHON
+        if start > len(self._str):  # workaround to cope with corner case
+            return -1               # bugs in CPython 2.4 unicode.rfind('')
         return self._str.rfind(s._str, start, end)
 
     def ll_count(self, s, start, end):

Modified: pypy/dist/pypy/rpython/test/test_rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rstr.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rstr.py	Sat Jun  7 13:01:20 2008
@@ -281,9 +281,9 @@
             x+= s.find(const(''), i, i)*100
             x+= s.find(const(''), i, i+1)*1000
             return x
-        for i in range(5):
+        for i, expected in enumerate([0, 1110, 2220, 3330, -1110, -1110]):
             res = self.interpret(f, [i])
-            assert res == f(i)
+            assert res == expected
             
     def test_rfind(self):
         const = self.const
@@ -306,14 +306,14 @@
         def f(i):
             assert i >= 0
             s = const("abc")
-            x = s.find(const(''))
-            x+= s.find(const(''), i)*10
-            x+= s.find(const(''), i, i)*100
-            x+= s.find(const(''), i, i+1)*1000
+            x = s.rfind(const(''))
+            x+= s.rfind(const(''), i)*10
+            x+= s.rfind(const(''), i, i)*100
+            x+= s.rfind(const(''), i, i+1)*1000
             return x
-        for i in range(5):
+        for i, expected in enumerate([1033, 2133, 3233, 3333, 3-1110, 3-1110]):
             res = self.interpret(f, [i])
-            assert res == f(i)
+            assert res == expected
 
     def test_find_char(self):
         const = self.const



More information about the Pypy-commit mailing list