[pypy-svn] r48898 - in pypy/dist/pypy/rpython: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Nov 21 14:02:12 CET 2007


Author: cfbolz
Date: Wed Nov 21 14:02:11 2007
New Revision: 48898

Modified:
   pypy/dist/pypy/rpython/rstr.py
   pypy/dist/pypy/rpython/test/test_rstr.py
Log:
add support for "str in str"


Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py	(original)
+++ pypy/dist/pypy/rpython/rstr.py	Wed Nov 21 14:02:11 2007
@@ -371,6 +371,15 @@
         return hop.genop('int_gt', [vres, hop.inputconst(Signed, 0)],
                          resulttype=Bool)
 
+    def rtype_contains((r_str1, r_str2), hop):
+        v_str1, v_str2 = hop.inputargs(r_str1.repr, r_str2.repr)
+        v_end = hop.gendirectcall(r_str1.ll.ll_strlen, v_str1)
+        vres = hop.gendirectcall(r_str1.ll.ll_find, v_str1, v_str2,
+                                 hop.inputconst(Signed, 0), v_end)
+        return hop.genop('int_ne', [vres, hop.inputconst(Signed, -1)],
+                         resulttype=Bool)
+
+
 class __extend__(pairtype(AbstractStringRepr, AbstractCharRepr),
                  pairtype(AbstractUnicodeRepr, AbstractUniCharRepr)):
     def rtype_contains((r_str, r_chr), hop):

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	Wed Nov 21 14:02:11 2007
@@ -239,6 +239,18 @@
                 res = self.interpret(fn, [i,j])
                 assert res == fn(i, j)
 
+
+    def test_contains_str(self):
+        const = self.const
+        def fn(i, j):
+            s1 = [const('one two three'), const('abc abcdab abcdabcdabde')]
+            s2 = [const('one'), const('two'), const('abcdab'), const('one tou'), const('abcdefgh'), const('fortytwo'), const('')]
+            return s2[j] in s1[i]
+        for i in range(2):
+            for j in range(7):
+                res = self.interpret(fn, [i,j])
+                assert res == fn(i, j)
+
     def test_find_with_start(self):
         const = self.const
         def fn(i):



More information about the Pypy-commit mailing list