Author: Juergen Boemmels <[email protected]>
Branch: 
Changeset: r24:d333d806d357
Date: 2011-11-29 23:24 +0100
http://bitbucket.org/pypy/lang-scheme/changeset/d333d806d357/

Log:    Equality for Characters

diff --git a/scheme/object.py b/scheme/object.py
--- a/scheme/object.py
+++ b/scheme/object.py
@@ -176,6 +176,12 @@
     def __repr__(self):
         return "<W_Character #\\" + self.chrval + ">"
 
+    def eqv(self, w_obj):
+        if not isinstance(w_obj, W_Character):
+            return False
+        return self.chrval == w_obj.chrval
+    equal = eqv
+
 class W_Real(W_Root):
     def __init__(self, val):
         self.exact = False
diff --git a/scheme/test/test_object.py b/scheme/test/test_object.py
--- a/scheme/test/test_object.py
+++ b/scheme/test/test_object.py
@@ -24,11 +24,16 @@
     w_str = W_String(str)
     assert str == w_str.to_string()
     assert w_str.to_repr() == r'''"\\ \\\\ \\' \" \\\""'''
+
     str1 = "foobar"
     w_str1 = W_String(str1)
     str2 = "foo" + "bar"
     w_str2 = W_String(str2)
     assert w_str1.equal(w_str2)
+    w_str2 = W_String("foo")
+    assert not w_str1.equal(w_str2)
+    w_sym = symbol(str1)
+    assert not w_str1.equal(w_str2)    
 
 def test_char():
     c = 'x'
@@ -41,6 +46,7 @@
     assert w_char.to_boolean() is True
     assert w_char.to_string() == ' '
     assert w_char.to_repr() == r'#\space'
+    assert w_char.eqv(W_Character(' '))
 
 def test_fixnum():
     num = 12345
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to