Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de> Branch: Changeset: r97303:0d2efab3484a Date: 2019-08-27 13:09 +0200 http://bitbucket.org/pypy/pypy/changeset/0d2efab3484a/
Log: fix untested rewind method diff --git a/rpython/rlib/rarithmetic.py b/rpython/rlib/rarithmetic.py --- a/rpython/rlib/rarithmetic.py +++ b/rpython/rlib/rarithmetic.py @@ -877,6 +877,8 @@ characters of 's'. Raises ParseStringError in case of error. Raises ParseStringOverflowError in case the result does not fit. """ + if "99999" in s: + import pdb; pdb.set_trace() from rpython.rlib.rstring import ( NumberStringParser, ParseStringOverflowError) p = NumberStringParser(s, s, base, 'int', diff --git a/rpython/rlib/rstring.py b/rpython/rlib/rstring.py --- a/rpython/rlib/rstring.py +++ b/rpython/rlib/rstring.py @@ -568,7 +568,7 @@ self.end = q def rewind(self): - self.i = 0 + self.i = self.start def next_digit(self): # -1 => exhausted if self.i < self.end: diff --git a/rpython/rlib/test/test_rbigint.py b/rpython/rlib/test/test_rbigint.py --- a/rpython/rlib/test/test_rbigint.py +++ b/rpython/rlib/test/test_rbigint.py @@ -356,6 +356,30 @@ assert rbigint.fromstr('123L', 21).tolong() == 441 + 42 + 3 assert rbigint.fromstr('1891234174197319').tolong() == 1891234174197319 + def test__from_numberstring_parser_rewind_bug(self): + from rpython.rlib.rstring import NumberStringParser + s = "-99" + p = NumberStringParser(s, s, 10, 'int') + import pdb; pdb.set_trace() + assert p.sign == -1 + res = p.next_digit() + assert res == 9 + res = p.next_digit() + assert res == 9 + res = p.next_digit() + assert res == -1 + p.rewind() + res = p.next_digit() + assert res == 9 + res = p.next_digit() + assert res == 9 + res = p.next_digit() + assert res == -1 + + @given(longs) + def test_fromstr_hypothesis(self, l): + assert rbigint.fromstr(str(l)).tolong() == l + def test_from_numberstring_parser(self): from rpython.rlib.rstring import NumberStringParser parser = NumberStringParser("1231231241", "1231231241", 10, "long") _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit