[pypy-svn] r10756 - in pypy/dist/pypy/objspace/std: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Sun Apr 17 00:36:17 CEST 2005


Author: cfbolz
Date: Sun Apr 17 00:36:17 2005
New Revision: 10756

Modified:
   pypy/dist/pypy/objspace/std/boolobject.py
   pypy/dist/pypy/objspace/std/test/test_boolobject.py
Log:
Added and_, or_ and xor implementation to bool. Until now True | True returned 1.

Modified: pypy/dist/pypy/objspace/std/boolobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/boolobject.py	(original)
+++ pypy/dist/pypy/objspace/std/boolobject.py	Sun Apr 17 00:36:17 2005
@@ -36,6 +36,15 @@
     else:
         return space.wrap('False')
 
+def and__Bool_Bool(space, w_bool1, w_bool2):
+    return space.newbool(w_bool1.boolval & w_bool2.boolval)
+
+def or__Bool_Bool(space, w_bool1, w_bool2):
+    return space.newbool(w_bool1.boolval | w_bool2.boolval)
+
+def xor__Bool_Bool(space, w_bool1, w_bool2):
+    return space.newbool(w_bool1.boolval ^ w_bool2.boolval)
+
 str__Bool = repr__Bool
 
 register_all(vars())

Modified: pypy/dist/pypy/objspace/std/test/test_boolobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_boolobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_boolobject.py	Sun Apr 17 00:36:17 2005
@@ -31,3 +31,12 @@
         assert "False" == str(False)
         assert "True" == repr(True)
         assert "False" == repr(False)
+
+    def test_bool_ops(self):
+        assert True + True == 2
+        assert False | False is False
+        assert True | False is True
+        assert True & True is True
+        assert True ^ True is False
+        assert False ^ False is False
+        assert True ^ False is True
\ No newline at end of file



More information about the Pypy-commit mailing list