From 007f19ea494ebf727966eb6fed2ba52b622bf5b8 Mon Sep 17 00:00:00 2001 From: sulyi Date: Mon, 12 Dec 2016 15:19:25 +0100 Subject: [PATCH] [jsinterp] Adding code to parser tests --- test/test_jsinterp_parser.py | 55 +++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/test/test_jsinterp_parser.py b/test/test_jsinterp_parser.py index 6c533b32d..8381412ee 100644 --- a/test/test_jsinterp_parser.py +++ b/test/test_jsinterp_parser.py @@ -773,9 +773,9 @@ class TestJSInterpreterParser(unittest.TestCase): def test_for_empty(self): # ASAP for empty statement test jsi = JSInterpreter(''' - function f(){ + function f(x){ var h = 0 - for (; h < 2; ++h) { + for (; h <= x; ++h) { a = h; } return a @@ -798,17 +798,33 @@ class TestJSInterpreterParser(unittest.TestCase): ast = [] self.assertEqual(list(jsi.statements()), ast) - @unittest.skip('Test not yet implemented: missing code and ast') + @unittest.skip('Test not yet implemented: missing ast') def test_do(self): # ASAP do statement test - jsi = JSInterpreter('') + jsi = JSInterpreter(''' + function f(x){ + i = 1 + do{ + i++; + } while (i < x) + return i; + } + ''') ast = [] self.assertEqual(list(jsi.statements()), ast) - @unittest.skip('Test not yet implemented: missing code and ast') + @unittest.skip('Test not yet implemented: missing ast') def test_while(self): # ASAP while statement test - jsi = JSInterpreter('') + jsi = JSInterpreter(''' + function f(x){ + i = 1 + while (i < x) { + i++; + } + return i; + } + ''') ast = [] self.assertEqual(list(jsi.statements()), ast) @@ -820,17 +836,36 @@ class TestJSInterpreterParser(unittest.TestCase): ast = [] self.assertEqual(list(jsi.statements()), ast) - @unittest.skip('Test not yet implemented: missing code and ast') + @unittest.skip('Test not yet implemented: missing ast') def test_funct_expr(self): # ASAP function expression test - jsi = JSInterpreter('') + jsi = JSInterpreter(''' + function f() { + var add = (function () { + var counter = 0; + return function () {return counter += 1;} + })(); + add(); + add(); + return add(); + } + ''') ast = [] self.assertEqual(list(jsi.statements()), ast) - @unittest.skip('Test not yet implemented: missing code and ast') + @unittest.skip('Test not yet implemented: missing ast') def test_object(self): # ASAP object literal test - jsi = JSInterpreter('') + jsi = JSInterpreter(''' + function f() { + var o = { + a: 7, + get b() { return this.a + 1; }, + set c(x) { this.a = x / 2; } + }; + return o; + } + ''') ast = [] self.assertEqual(list(jsi.statements()), ast)