[pypy-svn] r65476 - in pypy/branch/io-lang/pypy/lang/io: . test

david at codespeak.net david at codespeak.net
Thu May 28 13:41:00 CEST 2009


Author: david
Date: Thu May 28 13:40:58 2009
New Revision: 65476

Modified:
   pypy/branch/io-lang/pypy/lang/io/object.py
   pypy/branch/io-lang/pypy/lang/io/test/test_object.py
Log:
Added Object substract which returns negative version of a given number

Modified: pypy/branch/io-lang/pypy/lang/io/object.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/object.py	(original)
+++ pypy/branch/io-lang/pypy/lang/io/object.py	Thu May 28 13:40:58 2009
@@ -1,5 +1,5 @@
 from pypy.lang.io.register import register_method
-from pypy.lang.io.model import W_ImmutableSequence, W_Block
+from pypy.lang.io.model import W_ImmutableSequence, W_Block, W_Number
 
 @register_method('Object', 'setSlot', unwrap_spec=[object, str, object])
 def w_object_set_slot(space, w_target, name, w_value):
@@ -61,4 +61,8 @@
 
 @register_method('Object', 'message')
 def object_message(space, w_target, w_message, w_context):
-    return w_message.arguments[0]
\ No newline at end of file
+    return w_message.arguments[0]
+    
+ at register_method('Object', '-', unwrap_spec=[object, float])
+def object_minus(space, w_target, argument):
+    return W_Number(space, -argument)
\ No newline at end of file

Modified: pypy/branch/io-lang/pypy/lang/io/test/test_object.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/test/test_object.py	(original)
+++ pypy/branch/io-lang/pypy/lang/io/test/test_object.py	Thu May 28 13:40:58 2009
@@ -43,4 +43,12 @@
     inp = 'message(foo)'
     res, space = interpret(inp)
     assert isinstance(res, W_Message)
-    assert res.name == 'foo'
\ No newline at end of file
+    assert res.name == 'foo'
+    
+def test_object_substract():
+    inp = '-1'
+    res, space = interpret(inp)
+    assert res.value == -1
+    
+    inp = '-"a"'
+    py.test.raises(Exception, "interpret(inp)")
\ No newline at end of file



More information about the Pypy-commit mailing list