changeset 137:f83a1603c417

Added a syntax error test.
author Atul Varma <varmaa@toolness.com>
date Sun, 23 Aug 2009 21:59:39 -0700
parents b4e216d06e83
children 1a982ee56458
files tests/test_pymonkey.py
diffstat 1 files changed, 17 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test_pymonkey.py	Sun Aug 23 21:49:44 2009 -0700
+++ b/tests/test_pymonkey.py	Sun Aug 23 21:59:39 2009 -0700
@@ -15,6 +15,14 @@
         cx.init_standard_classes(obj)
         return cx.evaluate_script(obj, code, '<string>', 1)
 
+    def _execjs(self, code):
+        rt = pymonkey.Runtime()
+        cx = rt.new_context()
+        obj = cx.new_object()
+        cx.init_standard_classes(obj)
+        script = cx.compile_script(obj, code, '<string>', 1)
+        return cx.execute_script(obj, script)
+
     def _evalJsWrappedPyFunc(self, func, code):
         cx = pymonkey.Runtime().new_context()
         obj = cx.new_object()
@@ -32,14 +40,16 @@
             was_raised = True
         self.assertTrue(was_raised)
 
+    def testSyntaxErrorsAreRaised(self):
+        for run in [self._evaljs, self._execjs]:
+            self.assertRaises(pymonkey.error, run, '5f')
+            self.assertEqual(
+                self.last_exception.args[1],
+                u'SyntaxError: missing ; before statement'
+                )
+
     def testCompileScriptWorks(self):
-        rt = pymonkey.Runtime()
-        cx = rt.new_context()
-        obj = cx.new_object()
-        cx.init_standard_classes(obj)
-        code = '5 + 1'
-        script = cx.compile_script(obj, code, '<string>', 1)
-        self.assertEqual(cx.execute_script(obj, script), 6)
+        self.assertEqual(self._execjs('5 + 1'), 6)
 
     def testErrorsRaisedIncludeStrings(self):
         self.assertRaises(pymonkey.error, self._evaljs, 'boop()')