[pypy-commit] pypy default: Tests and fix for ``for c in string'' when the string turns out
arigo
noreply at buildbot.pypy.org
Mon Dec 12 15:34:36 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r50427:5ba9f567b515
Date: 2011-12-12 15:17 +0100
http://bitbucket.org/pypy/pypy/changeset/5ba9f567b515/
Log: Tests and fix for ``for c in string'' when the string turns out to
be always a single character.
diff --git a/pypy/rpython/lltypesystem/rstr.py b/pypy/rpython/lltypesystem/rstr.py
--- a/pypy/rpython/lltypesystem/rstr.py
+++ b/pypy/rpython/lltypesystem/rstr.py
@@ -99,7 +99,7 @@
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
diff --git a/pypy/rpython/test/test_rstr.py b/pypy/rpython/test/test_rstr.py
--- a/pypy/rpython/test/test_rstr.py
+++ b/pypy/rpython/test/test_rstr.py
@@ -89,6 +89,28 @@
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):
More information about the pypy-commit
mailing list