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

antocuni at codespeak.net antocuni at codespeak.net
Mon May 15 14:17:49 CEST 2006


Author: antocuni
Date: Mon May 15 14:17:42 2006
New Revision: 27233

Modified:
   pypy/dist/pypy/rpython/ootypesystem/ootype.py
   pypy/dist/pypy/rpython/test/test_rstr.py
Log:
Added support for methods find, rfind, strip, upper and lower to
ootypesystem rstr.



Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py	Mon May 15 14:17:42 2006
@@ -281,8 +281,15 @@
             "ll_streq": Meth([self.SELFTYPE_T], Bool),
             "ll_strcmp": Meth([self.SELFTYPE_T], Signed),
             "ll_startswith": Meth([self.SELFTYPE_T], Bool),
-            "ll_endswith": Meth([self.SELFTYPE_T], Bool),            
-        })
+            "ll_endswith": Meth([self.SELFTYPE_T], Bool),
+            "ll_find": Meth([self.SELFTYPE_T, Signed, Signed], Signed),
+            "ll_rfind": Meth([self.SELFTYPE_T, Signed, Signed], Signed),
+            "ll_find_char": Meth([Char, Signed, Signed], Signed),
+            "ll_rfind_char": Meth([Char, Signed, Signed], Signed),
+            "ll_strip": Meth([Char, Bool, Bool], self.SELFTYPE_T),
+            "ll_upper": Meth([], self.SELFTYPE_T),
+            "ll_lower": Meth([], self.SELFTYPE_T),
+            })
         self._setup_methods(generic_types)
 
     # TODO: should it return _null or ''?
@@ -827,6 +834,40 @@
         # NOT_RPYTHON
         return self._str.endswith(s._str)
 
+    def ll_find(self, s, start, end):
+        # NOT_RPYTHON
+        return self._str.find(s._str, start, end)
+
+    def ll_rfind(self, s, start, end):
+        # NOT_RPYTHON
+        return self._str.rfind(s._str, start, end)
+
+    def ll_find_char(self, ch, start, end):
+        # NOT_RPYTHON
+        return self._str.find(ch, start, end)
+
+    def ll_rfind_char(self, ch, start, end):
+        # NOT_RPYTHON
+        return self._str.rfind(ch, start, end)
+
+    def ll_strip(self, ch, left, right):
+        # NOT_RPYTHON
+        s = self._str
+        if left:
+            s = s.lstrip(ch)
+        if right:
+            s = s.rstrip(ch)
+        return make_string(s)
+
+    def ll_upper(self):
+        # NOT_RPYTHON
+        return make_string(self._str.upper())
+
+    def ll_lower(self):
+        # NOT_RPYTHON
+        return make_string(self._str.lower())
+
+
 class _null_string(_null_mixin(_string), _string):
     def __init__(self, STRING):
         self.__dict__["_TYPE"] = STRING

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	Mon May 15 14:17:42 2006
@@ -249,79 +249,81 @@
                 res = self.interpret(fn, [i,j])
                 assert res is fn(i, j)
 
-def test_find():
-    def fn(i, j):
-        s1 = ['one two three', 'abc abcdab abcdabcdabde']
-        s2 = ['one', 'two', 'abcdab', 'one tou', 'abcdefgh', 'fortytwo', '']
-        return s1[i].find(s2[j])
-    for i in range(2):
-        for j in range(7):
-            res = interpret(fn, [i,j])
-            assert res == fn(i, j)
-
-def test_find_with_start():
-    def fn(i):
-        assert i >= 0
-        return 'ababcabc'.find('abc', i)
-    for i in range(9):
-        res = interpret(fn, [i])
-        assert res == fn(i)
-
-def test_find_with_start_end():
-    def fn(i, j):
-        assert i >= 0
-        assert j >= 0
-        return 'ababcabc'.find('abc', i, j)
-    for (i, j) in [(1,7), (2,6), (3,7), (3,8)]:
-        res = interpret(fn, [i, j])
-        assert res == fn(i, j)
+    def test_find(self):
+        def fn(i, j):
+            s1 = ['one two three', 'abc abcdab abcdabcdabde']
+            s2 = ['one', 'two', 'abcdab', 'one tou', 'abcdefgh', 'fortytwo', '']
+            return s1[i].find(s2[j])
+        for i in range(2):
+            for j in range(7):
+                res = self.interpret(fn, [i,j])
+                assert res == fn(i, j)
 
-def test_rfind():
-    def fn():
-        return 'aaa'.rfind('a') + 'aaa'.rfind('a', 1) + 'aaa'.rfind('a', 1, 2)
-    res = interpret(fn, [])
-    assert res == 2 + 2 + 1
-
-def test_find_char():
-    def fn(ch):
-        pos1 = 'aiuwraz 483'.find(ch)
-        pos2 = 'aiuwraz 483'.rfind(ch)
-        return pos1 + (pos2*100)
-    for ch in 'a ?3':
-        res = interpret(fn, [ch])
-        assert res == fn(ch)
-
-def test_strip():
-    def both():
-        return '!ab!'.strip('!')
-    def left():
-        return '!ab!'.lstrip('!')
-    def right():
-        return '!ab!'.rstrip('!')
-    res = interpret(both, [])
-    assert ''.join(res.chars) == 'ab'
-    res = interpret(left, [])
-    assert ''.join(res.chars) == 'ab!'
-    res = interpret(right, [])
-    assert ''.join(res.chars) == '!ab'
-
-def test_upper():
-    strings = ['', ' ', 'upper', 'UpPeR', ',uppEr,']
-    for i in range(256): strings.append(chr(i))
-    def fn(i):
-        return strings[i].upper()
-    for i in range(len(strings)):
-        res = interpret(fn, [i])
-        assert ''.join(res.chars) == fn(i)
+    def test_find_with_start(self):
+        self._skip_oo('assert')
+        def fn(i):
+            assert i >= 0
+            return 'ababcabc'.find('abc', i)
+        for i in range(9):
+            res = self.interpret(fn, [i])
+            assert res == fn(i)
+
+    def test_find_with_start_end(self):
+        self._skip_oo('assert')
+        def fn(i, j):
+            assert i >= 0
+            assert j >= 0
+            return 'ababcabc'.find('abc', i, j)
+        for (i, j) in [(1,7), (2,6), (3,7), (3,8)]:
+            res = self.interpret(fn, [i, j])
+            assert res == fn(i, j)
 
-def test_lower():
-    strings = ['', ' ', 'lower', 'LoWeR', ',lowEr,']
-    for i in range(256): strings.append(chr(i))
-    def fn(i):
-        return strings[i].lower()
-    for i in range(len(strings)):
-        res = interpret(fn, [i])
-        assert ''.join(res.chars) == fn(i)
+    def test_rfind(self):
+        def fn():
+            return 'aaa'.rfind('a') + 'aaa'.rfind('a', 1) + 'aaa'.rfind('a', 1, 2)
+        res = self.interpret(fn, [])
+        assert res == 2 + 2 + 1
+
+    def test_find_char(self):
+        def fn(ch):
+            pos1 = 'aiuwraz 483'.find(ch)
+            pos2 = 'aiuwraz 483'.rfind(ch)
+            return pos1 + (pos2*100)
+        for ch in 'a ?3':
+            res = self.interpret(fn, [ch])
+            assert res == fn(ch)
+
+    def test_strip(self):
+        def both():
+            return '!ab!'.strip('!')
+        def left():
+            return '!ab!'.lstrip('!')
+        def right():
+            return '!ab!'.rstrip('!')
+        res = self.interpret(both, [])
+        assert self.ll_to_string(res) == 'ab'
+        res = self.interpret(left, [])
+        assert self.ll_to_string(res) == 'ab!'
+        res = self.interpret(right, [])
+        assert self.ll_to_string(res) == '!ab'
+
+    def test_upper(self):
+        strings = ['', ' ', 'upper', 'UpPeR', ',uppEr,']
+        for i in range(256): strings.append(chr(i))
+        def fn(i):
+            return strings[i].upper()
+        for i in range(len(strings)):
+            res = self.interpret(fn, [i])
+            assert self.ll_to_string(res) == fn(i)
+
+    def test_lower(self):
+        strings = ['', ' ', 'lower', 'LoWeR', ',lowEr,']
+        for i in range(256): strings.append(chr(i))
+        def fn(i):
+            return strings[i].lower()
+        for i in range(len(strings)):
+            res = self.interpret(fn, [i])
+            assert self.ll_to_string(res) == fn(i)
 
 def test_join():
     res = interpret(lambda: ''.join([]), [])



More information about the Pypy-commit mailing list