[pypy-svn] r58952 - in pypy/branch/getslice/pypy/objspace/flow: . test

arigo at codespeak.net arigo at codespeak.net
Sat Oct 11 11:38:41 CEST 2008


Author: arigo
Date: Sat Oct 11 11:38:40 2008
New Revision: 58952

Modified:
   pypy/branch/getslice/pypy/objspace/flow/operation.py
   pypy/branch/getslice/pypy/objspace/flow/test/test_objspace.py
Log:
Improve test and fix it.


Modified: pypy/branch/getslice/pypy/objspace/flow/operation.py
==============================================================================
--- pypy/branch/getslice/pypy/objspace/flow/operation.py	(original)
+++ pypy/branch/getslice/pypy/objspace/flow/operation.py	Sat Oct 11 11:38:40 2008
@@ -134,6 +134,16 @@
 def lshift_ovf(x, y):
     return ovfcheck_lshift(x, y)
 
+# slicing: operator.{get,set,del}slice() don't support b=None or c=None
+def do_getslice(a, b, c):
+    return a[b:c]
+
+def do_setslice(a, b, c, d):
+    a[b:c] = d
+
+def do_delslice(a, b, c):
+    del a[b:c]
+
 # ____________________________________________________________
 
 # The following table can list several times the same operation name,
@@ -190,6 +200,9 @@
     ('delete',          delete),
     ('userdel',         userdel),
     ('buffer',          buffer),
+    ('getslice',        do_getslice),
+    ('setslice',        do_setslice),
+    ('delslice',        do_delslice),
     # --- operations added by graph transformations ---
     ('neg_ovf',         neg_ovf),
     ('abs_ovf',         abs_ovf),

Modified: pypy/branch/getslice/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/branch/getslice/pypy/objspace/flow/test/test_objspace.py	(original)
+++ pypy/branch/getslice/pypy/objspace/flow/test/test_objspace.py	Sat Oct 11 11:38:40 2008
@@ -852,11 +852,29 @@
         py.test.raises(RuntimeError, "self.codetest(f)")
 
     def test_getslice_constfold(self):
-        def f():
+        def check(f, expected):
+            graph = self.codetest(f)
+            assert graph.startblock.operations == []
+            [link] = graph.startblock.exits
+            assert link.target is graph.returnblock
+            assert isinstance(link.args[0], Constant)
+            assert link.args[0].value == expected
+
+        def f1():
+            s = 'hello'
+            return s[:-2]
+        check(f1, 'hel')
+
+        def f2():
             s = 'hello'
-            return s[:3]
-        graph = self.codetest(f)
-        assert not self.all_operations(graph)
+            return s[:]
+        check(f2, 'hello')
+
+        def f3():
+            s = 'hello'
+            return s[-3:]
+        check(f3, 'llo')
+
 
 class TestFlowObjSpaceDelay(Base):
     def setup_class(cls):



More information about the Pypy-commit mailing list