[pypy-commit] pypy default: what isn't tested is broken

cfbolz noreply at buildbot.pypy.org
Mon Jun 17 14:35:22 CEST 2013


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: 
Changeset: r64907:33f5229fbc8a
Date: 2013-06-14 17:52 +0200
http://bitbucket.org/pypy/pypy/changeset/33f5229fbc8a/

Log:	what isn't tested is broken

diff --git a/rpython/rlib/rstring.py b/rpython/rlib/rstring.py
--- a/rpython/rlib/rstring.py
+++ b/rpython/rlib/rstring.py
@@ -13,7 +13,10 @@
 
 @specialize.argtype(0)
 def split(value, by, maxsplit=-1):
-    assert type(value) == type(by)
+    if isinstance(value, str):
+        assert isinstance(by, str)
+    else:
+        assert isinstance(by, unicode)
     bylen = len(by)
     if bylen == 0:
         raise ValueError("empty separator")
@@ -28,6 +31,7 @@
         res = newlist_hint(count + 1)
         while count > 0:
             next = value.find(by, start)
+            assert next >= 0 # cannot fail due to the value.count above
             res.append(value[start:next])
             start = next + bylen
             count -= 1
@@ -53,7 +57,10 @@
 
 @specialize.argtype(0)
 def rsplit(value, by, maxsplit=-1):
-    assert type(value) == type(by)
+    if isinstance(value, str):
+        assert isinstance(by, str)
+    else:
+        assert isinstance(by, unicode)
     if maxsplit > 0:
         res = newlist_hint(min(maxsplit + 1, len(value)))
     else:
diff --git a/rpython/rlib/test/test_rstring.py b/rpython/rlib/test/test_rstring.py
--- a/rpython/rlib/test/test_rstring.py
+++ b/rpython/rlib/test/test_rstring.py
@@ -1,6 +1,7 @@
 import sys, py
 
 from rpython.rlib.rstring import StringBuilder, UnicodeBuilder, split, rsplit
+from rpython.rtyper.test.tool import BaseRtypingTest, LLRtypeMixin
 
 def test_split():
     assert split("", 'x') == ['']
@@ -64,4 +65,22 @@
     s.append_multiple_char(u'd', 4)
     assert s.build() == 'aabcbdddd'
     assert isinstance(s.build(), unicode)
-        
+
+
+class TestTranslates(LLRtypeMixin, BaseRtypingTest):
+    def test_split_rsplit_translate(self):
+        def fn():
+            res = True
+            res = res and split('a//b//c//d', '//') == ['a', 'b', 'c', 'd']
+            res = res and split('a//b//c//d', '//', 2) == ['a', 'b', 'c//d']
+            res = res and split(u'a//b//c//d', u'//') == [u'a', u'b', u'c', u'd']
+            res = res and split(u'endcase test', u'test') == [u'endcase ', u'']
+            res = res and rsplit('a|b|c|d', '|', 2) == ['a|b', 'c', 'd']
+            res = res and rsplit('a//b//c//d', '//') == ['a', 'b', 'c', 'd']
+            res = res and rsplit(u'a|b|c|d', u'|') == [u'a', u'b', u'c', u'd']
+            res = res and rsplit(u'a|b|c|d', u'|', 2) == [u'a|b', u'c', u'd']
+            res = res and rsplit(u'a//b//c//d', u'//') == [u'a', u'b', u'c', u'd']
+            return res
+        res = self.interpret(fn, [])
+        assert res
+


More information about the pypy-commit mailing list