[pypy-svn] r38487 - in pypy/dist/pypy: module/__builtin__/test objspace/std objspace/std/test
arigo at codespeak.net
arigo at codespeak.net
Sun Feb 11 18:14:39 CET 2007
Author: arigo
Date: Sun Feb 11 18:14:37 2007
New Revision: 38487
Modified:
pypy/dist/pypy/module/__builtin__/test/test_builtin.py
pypy/dist/pypy/objspace/std/test/test_unicodeobject.py
pypy/dist/pypy/objspace/std/unicodeobject.py
Log:
Fix for (u'hello' == 5). Implementing comparison with cmp__X_X() is not
a great idea...
Modified: pypy/dist/pypy/module/__builtin__/test/test_builtin.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/test/test_builtin.py (original)
+++ pypy/dist/pypy/module/__builtin__/test/test_builtin.py Sun Feb 11 18:14:37 2007
@@ -270,6 +270,8 @@
assert cmp(9,9) == 0
assert cmp(0,9) < 0
assert cmp(9,0) > 0
+ assert cmp("abc", 12) != 0
+ assert cmp(u"abc", 12) != 0
def test_cmp_more(self):
class C:
Modified: pypy/dist/pypy/objspace/std/test/test_unicodeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_unicodeobject.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_unicodeobject.py Sun Feb 11 18:14:37 2007
@@ -1,16 +1,17 @@
-# test the integration of unicode and strings (even though we don't
-# really implement unicode yet).
-
import autopath, sys
-
class AppTestUnicodeStringStdOnly:
def test_compares(self):
assert u'a' == 'a'
assert 'a' == u'a'
- assert not u'a' == 'b' # xxx u'a' != 'b' fails
- assert not 'a' == u'b'# xxx 'a' != u'b' fails
+ assert not u'a' == 'b'
+ assert not 'a' == u'b'
+ assert u'a' != 'b'
+ assert 'a' != u'b'
+ assert not (u'a' == 5)
+ assert u'a' != 5
+ assert u'a' < 5 or u'a' > 5
class AppTestUnicodeString:
def test_addition(self):
Modified: pypy/dist/pypy/objspace/std/unicodeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/unicodeobject.py (original)
+++ pypy/dist/pypy/objspace/std/unicodeobject.py Sun Feb 11 18:14:37 2007
@@ -65,30 +65,16 @@
def str__Unicode(space, w_uni):
return space.call_method(w_uni, 'encode')
-def cmp__Unicode_Unicode(space, w_left, w_right):
+def eq__Unicode_Unicode(space, w_left, w_right):
+ return space.newbool(w_left._value == w_right._value)
+
+def lt__Unicode_Unicode(space, w_left, w_right):
left = w_left._value
right = w_right._value
for i in range(min(len(left), len(right))):
- test = ord(left[i]) - ord(right[i])
- if test < 0:
- return space.wrap(-1)
- if test > 0:
- return space.wrap(1)
-
- test = len(left) - len(right)
- if test < 0:
- return space.wrap(-1)
- if test > 0:
- return space.wrap(1)
- return space.wrap(0)
-
-## XXX what?? the following seems unnecessary
-##def cmp__Unicode_ANY(space, w_left, w_right):
-## try:
-## w_right = space.call_function(space.w_unicode, w_right)
-## except:
-## return space.wrap(1)
-## return space.cmp(w_left, w_right)
+ if left[i] != right[i]:
+ return space.newbool(left[i] < right[i])
+ return space.newbool(len(left) < len(right))
def ord__Unicode(space, w_uni):
if len(w_uni._value) != 1:
More information about the Pypy-commit
mailing list