Commits

Armin Rigo committed 5ba9f56

Tests and fix for ``for c in string'' when the string turns out
to be always a single character.

  • Participants
  • Parent commits 1a9a443

Comments (0)

Files changed (2)

pypy/rpython/lltypesystem/rstr.py

             return p
 
     def make_iterator_repr(self):
-        return self.iterator_repr
+        return self.repr.iterator_repr
 
     def can_ll_be_null(self, s_value):
         # XXX unicode

pypy/rpython/test/test_rstr.py

             res = self.interpret(fn, [i])
             assert res is True
 
+    def test_iter_over_char(self):
+        const = self.const
+        def fn(i):
+            for c in const('a'):
+                i += ord(c) + 10000
+            return i
+        res = self.interpret(fn, [0])
+        assert res == ord('a') + 10000
+
+    def test_iter_over_nonconst_char(self):
+        const = self.const
+        def fn(i):
+            if i > 0:
+                c = const('a')
+            else:
+                c = const('A')
+            for c in c:
+                i += ord(c) + 10000
+            return i
+        res = self.interpret(fn, [1])
+        assert res == 1 + ord('a') + 10000
+
     def test_char_constant(self):
         const = self.const
         def fn(s):