[pypy-commit] pypy enumerate-rstr: Proper tests and some oothingies.
jerith
noreply at buildbot.pypy.org
Thu Feb 21 19:36:50 CET 2013
Author: Jeremy Thurgood <firxen at gmail.com>
Branch: enumerate-rstr
Changeset: r61557:5671340d830e
Date: 2013-02-21 20:36 +0200
http://bitbucket.org/pypy/pypy/changeset/5671340d830e/
Log: Proper tests and some oothingies.
diff --git a/rpython/rtyper/ootypesystem/rstr.py b/rpython/rtyper/ootypesystem/rstr.py
--- a/rpython/rtyper/ootypesystem/rstr.py
+++ b/rpython/rtyper/ootypesystem/rstr.py
@@ -428,14 +428,17 @@
class StringIteratorRepr(AbstractStringIteratorRepr):
+ external_item_repr = char_repr
lowleveltype = ootype.Record({'string': string_repr.lowleveltype,
'index': ootype.Signed})
def __init__(self):
self.ll_striter = ll_striter
self.ll_strnext = ll_strnext
+ self.ll_getnextindex = ll_getnextindex
class UnicodeIteratorRepr(AbstractStringIteratorRepr):
+ external_item_repr = unichar_repr
lowleveltype = ootype.Record({'string': unicode_repr.lowleveltype,
'index': ootype.Signed})
@@ -463,6 +466,9 @@
iter.index = index + 1
return string.ll_stritem_nonneg(index)
+def ll_getnextindex(iter):
+ return iter.index
+
StringRepr.string_iterator_repr = StringIteratorRepr()
UnicodeRepr.string_iterator_repr = UnicodeIteratorRepr()
diff --git a/rpython/rtyper/test/test_rstr.py b/rpython/rtyper/test/test_rstr.py
--- a/rpython/rtyper/test/test_rstr.py
+++ b/rpython/rtyper/test/test_rstr.py
@@ -1035,6 +1035,17 @@
got = self.interpret(f, [7])
assert self.ll_to_string(got) == 'None'
+ def test_enumerate(self):
+ const = self.const
+ def fn(n):
+ s = const('abcde')
+ for i, x in enumerate(s):
+ if i == n:
+ return x
+ return 'x'
+ res = self.interpret(fn, [2])
+ assert res == 'c'
+
def FIXME_test_str_to_pystringobj():
def f(n):
More information about the pypy-commit
mailing list