diff test_pymonkey.py @ 31:d0a3f358072a

gcc now shows all warnings (-Wall). JS-wrapped Python functions can now return integers.
author Atul Varma <varmaa@toolness.com>
date Tue, 30 Jun 2009 22:28:04 -0700
parents 608d086d12e3
children abf14cba9ef5
line wrap: on
line diff
--- a/test_pymonkey.py	Tue Jun 30 21:53:45 2009 -0700
+++ b/test_pymonkey.py	Tue Jun 30 22:28:04 2009 -0700
@@ -9,19 +9,36 @@
         cx.init_standard_classes(obj)
         return cx.evaluate_script(obj, code, '<string>', 1)
 
-    def testJsWrappedPythonFunctionReturnsUnicode(self):
+    def _evalJsWrappedPyFunc(self, func, code):
         cx = pymonkey.Runtime().new_context()
         obj = cx.new_object()
         cx.init_standard_classes(obj)
+        cx.define_function(obj, func, func.__name__)
+        return cx.evaluate_script(obj, code, '<string>', 1)
 
+    def testJsWrappedPythonFunctionReturnsUnicode(self):
         def hai2u():
             return u"o hai"
+        self.assertEqual(self._evalJsWrappedPyFunc(hai2u, 'hai2u()'),
+                         u"o hai")
 
-        cx.define_function(obj, hai2u, "hai2u")
-        self.assertEqual(
-            cx.evaluate_script(obj, 'hai2u()', '<string>', 1),
-            u"o hai"
-            )
+    def testJsWrappedPythonFunctionReturnsSmallInt(self):
+        def hai2u():
+            return 5
+        self.assertEqual(self._evalJsWrappedPyFunc(hai2u, 'hai2u()'),
+                         5)
+
+    def testJsWrappedPythonFunctionReturnsNegativeInt(self):
+        def hai2u():
+            return -5
+        self.assertEqual(self._evalJsWrappedPyFunc(hai2u, 'hai2u()'),
+                         -5)
+
+    def testJsWrappedPythonFunctionReturnsBigInt(self):
+        def hai2u():
+            return 2147483647
+        self.assertEqual(self._evalJsWrappedPyFunc(hai2u, 'hai2u()'),
+                         2147483647)
 
     def testObjectIsIdentityPreserving(self):
         cx = pymonkey.Runtime().new_context()
@@ -104,6 +121,13 @@
     def testEvaluateReturnsIntegers(self):
         self.assertEqual(self._evaljs('1+3'), 4)
 
+    def testEvaluateReturnsNegativeIntegers(self):
+        self.assertEqual(self._evaljs('-5'), -5)
+
+    def testEvaluateReturnsBigIntegers(self):
+        self.assertEqual(self._evaljs('2147483647*2'),
+                         2147483647*2)
+
     def testEvaluateReturnsFloats(self):
         self.assertEqual(self._evaljs('1.1+3'), 4.1)