extended test cases for type inference in generators
authorStefan Behnel <scoder@users.berlios.de>
Thu, 7 Apr 2011 12:18:47 +0000 (14:18 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Thu, 7 Apr 2011 12:18:47 +0000 (14:18 +0200)
tests/run/generator_type_inference.pyx

index d8c7c8525cefb9b556d674e5b26569a0783d633f..6a5c90e91c80c9188b3723517c8334bf04af625d 100644 (file)
@@ -5,9 +5,48 @@ cimport cython
 
 def test_type_inference():
     """
-    >>> [ item for item in test_type_inference() ]
+    >>> list(test_type_inference())
     [(2.0, 'double'), (2.0, 'double'), (2.0, 'double')]
     """
     x = 1.0
     for i in range(3):
         yield x * 2.0, cython.typeof(x)
+
+def test_unicode_loop():
+    """
+    >>> chars = list(test_unicode_loop())
+    1 Py_UCS4
+    2 Py_UCS4
+    2 Py_UCS4
+    2 Py_UCS4
+    2 Py_UCS4
+    >>> len(chars)
+    4
+    >>> ''.join(chars) == 'abcd'
+    True
+    """
+    ustr = u'abcd'
+    print 1, cython.typeof(ustr[0])
+    for c in ustr:
+        print 2, cython.typeof(c)
+        yield c
+
+def test_nonlocal_disables_inference():
+    """
+    >>> chars = list(test_nonlocal_disables_inference())
+    1 Python object
+    2 Python object
+    2 Python object
+    >>> len(chars)
+    2
+    >>> ''.join(chars) == 'ab'
+    True
+    """
+    ustr = u'ab'
+    print 1, cython.typeof(ustr[0])
+    def gen():
+        nonlocal ustr
+        for c in ustr:
+            print 2, cython.typeof(c)
+            yield c
+    return gen()