[pypy-svn] r48792 - in pypy/branch/ropes-unicode/pypy/objspace/std: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Nov 19 15:38:07 CET 2007
Author: cfbolz
Date: Mon Nov 19 15:38:06 2007
New Revision: 48792
Modified:
pypy/branch/ropes-unicode/pypy/objspace/std/ropeunicodeobject.py
pypy/branch/ropes-unicode/pypy/objspace/std/test/test_unicodeobject.py
Log:
fix a bug in rindex
Modified: pypy/branch/ropes-unicode/pypy/objspace/std/ropeunicodeobject.py
==============================================================================
--- pypy/branch/ropes-unicode/pypy/objspace/std/ropeunicodeobject.py (original)
+++ pypy/branch/ropes-unicode/pypy/objspace/std/ropeunicodeobject.py Mon Nov 19 15:38:06 2007
@@ -594,13 +594,13 @@
# XXX works but flattens string
self, start, end = _convert_idx_params(space, w_self, w_start, w_end)
self = self.flatten_unicode()
- sub = sub.flatten_unicode()
+ sub = w_substr._node.flatten_unicode()
res = self.rfind(sub, start, end)
if res < 0:
raise OperationError(space.w_ValueError,
space.wrap("substring not found in string.rindex"))
- return wrapint(space, res)
+ return space.wrap(res)
def unicode_count__RopeUnicode_RopeUnicode_ANY_ANY(space, w_self, w_substr, w_start, w_end):
self, start, end = _convert_idx_params(space, w_self, w_start, w_end)
Modified: pypy/branch/ropes-unicode/pypy/objspace/std/test/test_unicodeobject.py
==============================================================================
--- pypy/branch/ropes-unicode/pypy/objspace/std/test/test_unicodeobject.py (original)
+++ pypy/branch/ropes-unicode/pypy/objspace/std/test/test_unicodeobject.py Mon Nov 19 15:38:06 2007
@@ -503,3 +503,20 @@
raises(ValueError, S.rpartition, u'')
raises(TypeError, S.rpartition, None)
+
+
+ def test_rindex(self):
+ from sys import maxint
+ assert u'abcdefghiabc'.rindex(u'') == 12
+ assert u'abcdefghiabc'.rindex(u'def') == 3
+ assert u'abcdefghiabc'.rindex(u'abc') == 9
+ assert u'abcdefghiabc'.rindex(u'abc', 0, -1) == 0
+ assert u'abcdefghiabc'.rindex(u'abc', -4*maxint, 4*maxint) == 9
+ raises(ValueError, u'abcdefghiabc'.rindex, u'hib')
+ raises(ValueError, u'defghiabc'.rindex, u'def', 1)
+ raises(ValueError, u'defghiabc'.rindex, u'abc', 0, -1)
+ raises(ValueError, u'abcdefghi'.rindex, u'ghi', 0, 8)
+ raises(ValueError, u'abcdefghi'.rindex, u'ghi', 0, -1)
+ raises(TypeError, u'abcdefghijklmn'.rindex, u'abc', 0, 0.0)
+ raises(TypeError, u'abcdefghijklmn'.rindex, u'abc', -10.0, 30)
+
More information about the Pypy-commit
mailing list