[pypy-svn] r51834 - in pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk: . test

tverwaes at codespeak.net tverwaes at codespeak.net
Sun Feb 24 14:54:44 CET 2008


Author: tverwaes
Date: Sun Feb 24 14:54:42 2008
New Revision: 51834

Modified:
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py
Log:
fixing equivalent. for PointersObjects compares pointers unless chars. In that
case they are unwrapped and their value is compared.


Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py	Sun Feb 24 14:54:42 2008
@@ -134,6 +134,18 @@
         return (W_AbstractObjectWithIdentityHash.invariant(self) and
                 isinstance(self.w_class, W_PointersObject))
 
+    def equals(self, w_other):
+        # Special case:
+        # Chars are not compared by pointer but by char-value.
+        from pypy.lang.smalltalk.classtable import w_Character
+        from pypy.lang.smalltalk import utility
+        if self.getclass() == w_Character:
+            if w_other.getclass() != w_Character:
+                return False
+            else:
+                return utility.unwrap_char(self) == utility.unwrap_char(w_other)
+        else:
+            return self.pointer_equals(w_other)
 
 class W_PointersObject(W_AbstractObjectWithClassReference):
     """ The normal object """
@@ -276,6 +288,11 @@
                 return False
         return True
 
+    def equals(self, other):
+        if not isinstance(other, W_BytesObject):
+            return False
+        return self.bytes == other.bytes
+
 class W_WordsObject(W_AbstractObjectWithClassReference):
     def __init__(self, w_class, size):
         W_AbstractObjectWithClassReference.__init__(self, w_class)

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py	Sun Feb 24 14:54:42 2008
@@ -158,3 +158,12 @@
     test_not_equals(model.W_Float(100), model.W_SmallInteger(100))
     test_not_equals(model.W_Float(1.100), model.W_Float(1.200))
     test_not_equals(model.W_SmallInteger(101), model.W_SmallInteger(100))
+
+def test_charequals():
+    test_equals(utility.wrap_char('a'), utility.wrap_char('a'))
+    test_equals(utility.wrap_char('d'), utility.wrap_char('d'))
+
+def test_not_charequals():
+    test_not_equals(utility.wrap_char('a'), utility.wrap_char('d'))
+    test_not_equals(utility.wrap_char('d'), utility.wrap_int(3))
+    test_not_equals(utility.wrap_char('d'), utility.wrap_float(3.0))



More information about the Pypy-commit mailing list