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

pedronis at codespeak.net pedronis at codespeak.net
Wed Jul 20 17:41:39 CEST 2005


Author: pedronis
Date: Wed Jul 20 17:41:36 2005
New Revision: 14823

Modified:
   pypy/dist/pypy/rpython/rslice.py
   pypy/dist/pypy/rpython/test/test_rstr.py
   pypy/dist/pypy/rpython/test/test_rtyper.py
Log:
- another char*num test

- slice repr key was returning the same key for different repr choices, fix and some testing




Modified: pypy/dist/pypy/rpython/rslice.py
==============================================================================
--- pypy/dist/pypy/rpython/rslice.py	(original)
+++ pypy/dist/pypy/rpython/rslice.py	Wed Jul 20 17:41:36 2005
@@ -38,11 +38,16 @@
             return startonly_slice_repr
         else:
             return startstop_slice_repr
+        
     def rtyper_makekey(self):
-        return (self.__class__,
-                self.start.rtyper_makekey(),
-                self.stop.rtyper_makekey(),
-                self.step.rtyper_makekey())
+        if (self.start.is_constant() and self.start.const in (None, 0) and
+            self.stop.is_constant() and self.stop.const == -1):
+            kind = "minusone"    # [:-1]
+        elif self.stop.is_constant() and self.stop.const is None:
+            kind = "startonly"
+        else:
+            kind = "startstop"
+        return self.__class__, kind
 
 
 class SliceRepr(Repr):

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 Jul 20 17:41:36 2005
@@ -407,3 +407,10 @@
     res = interpret(f, ['a', 0])
     assert ''.join(res.chars) == ""
     
+def test_n_mul_char():
+    def f(c, n):
+        return n*c
+    res = interpret(f, ['a', 4])
+    assert ''.join(res.chars) == 'a'*4
+    res = interpret(f, ['a', 0])
+    assert ''.join(res.chars) == ""

Modified: pypy/dist/pypy/rpython/test/test_rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rtyper.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rtyper.py	Wed Jul 20 17:41:36 2005
@@ -13,7 +13,7 @@
 def teardown_module(mod): 
     py.log._setstate(mod.logstate) 
 
-def test_reprkey_dont_clash():
+def test_reprkeys_dont_clash():
     stup1 = annmodel.SomeTuple((annmodel.SomeFloat(), 
                                 annmodel.SomeInteger()))
     stup2 = annmodel.SomeTuple((annmodel.SomeString(), 
@@ -22,6 +22,35 @@
     key2 = stup2.rtyper_makekey()
     assert key1 != key2
 
+def test_slice_reprkeys():
+    one = annmodel.SomeInteger(nonneg=True)
+    one.const = 1
+    three = annmodel.SomeInteger(nonneg=True)
+    three.const = 3
+    minusone = annmodel.SomeInteger()
+    minusone.const = -1
+    none = annmodel.SomePBC({None: True})
+
+    startonly = annmodel.SomeSlice(one, none, none)
+    startonly2 = annmodel.SomeSlice(one, none, one)
+    startonly3 = annmodel.SomeSlice(three, none, one)    
+
+    startstop = annmodel.SomeSlice(one, one, none)
+    startstop2 = annmodel.SomeSlice(one, one, one)
+    startstop3 = annmodel.SomeSlice(one, three, none)
+
+    minusone_slice = annmodel.SomeSlice(none, minusone, none)
+    minusone_slice2 = annmodel.SomeSlice(none, minusone, one)
+
+    assert startonly.rtyper_makekey() == startonly2.rtyper_makekey() == startonly3.rtyper_makekey()
+    assert startstop.rtyper_makekey() == startstop2.rtyper_makekey() == startstop3.rtyper_makekey()
+    assert minusone_slice.rtyper_makekey() == minusone_slice2.rtyper_makekey()
+
+    assert startonly.rtyper_makekey() != startstop.rtyper_makekey()
+    assert startonly.rtyper_makekey() != minusone_slice.rtyper_makekey()
+    assert minusone_slice.rtyper_makekey() != startstop.rtyper_makekey()
+    
+
 def test_simple():
     def dummyfn(x):
         return x+1



More information about the Pypy-commit mailing list