[jsinterp] Adding code to if and switch test

This commit is contained in:
sulyi 2016-12-11 13:54:47 +01:00
parent ad49621758
commit c2e6ca5432
3 changed files with 69 additions and 2 deletions

View File

@ -45,6 +45,8 @@ class TestJSInterpreter(unittest.TestCase):
jsi = JSInterpreter('function $_xY1 ($_axY1) { var $_axY2 = $_axY1 + 1; return $_axY2; }') jsi = JSInterpreter('function $_xY1 ($_axY1) { var $_axY2 = $_axY1 + 1; return $_axY2; }')
self.assertEqual(jsi.call_function('$_xY1', 20), 21) self.assertEqual(jsi.call_function('$_xY1', 20), 21)
# TODO test prefix and postfix operators
def test_operators(self): def test_operators(self):
jsi = JSInterpreter('function f(){return 1 << 5;}') jsi = JSInterpreter('function f(){return 1 << 5;}')
self.assertEqual(jsi.call_function('f'), 32) self.assertEqual(jsi.call_function('f'), 32)

View File

@ -630,13 +630,79 @@ class TestJSInterpreterParser(unittest.TestCase):
] ]
self.assertEqual(list(jsi.statements()), ast) self.assertEqual(list(jsi.statements()), ast)
@unittest.skip('Incomplete test: missing code and ast') @unittest.skip('Test not yet implemented: missing ast')
def test_if(self): def test_if(self):
# TODO if test # TODO if test
jsi = JSInterpreter(
'''
function a(x) {
if (x > 0)
return true
else
return false
}
'''
)
ast = []
self.assertEqual(list(jsi.statements()), ast)
jsi = JSInterpreter(
'''
function a(x) {
if (x > 0)
return true
return false
}
'''
)
ast = []
self.assertEqual(list(jsi.statements()), ast)
jsi = JSInterpreter(
'''
function a(x) {
if (x > 0) {
x--;
return x;
} else {
x++;
return false;
}
}
'''
)
ast = []
self.assertEqual(list(jsi.statements()), ast)
@unittest.skip('Test not yet implemented: missing code and ast')
def test_with(self):
# TODO with test
jsi = JSInterpreter('') jsi = JSInterpreter('')
ast = [] ast = []
self.assertEqual(list(jsi.statements()), ast) self.assertEqual(list(jsi.statements()), ast)
@unittest.skip('Test not yet implemented: missing code and ast')
def test_switch(self):
# TODO switch test
jsi = JSInterpreter(
'''
function a(x) {
switch (x) {
case x == 6:
break;
case x > 5:
x++;
case x == 6:
x--;
default:
x = 0;
}
}
'''
)
ast = []
self.assertEqual(list(jsi.statements()), ast)
def test_unshift(self): def test_unshift(self):
# https://hg.mozilla.org/mozilla-central/file/tip/js/src/tests/ecma_5/Array/unshift-01.js # https://hg.mozilla.org/mozilla-central/file/tip/js/src/tests/ecma_5/Array/unshift-01.js
jsi = JSInterpreter( jsi = JSInterpreter(

View File

@ -1,5 +1,4 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from ..compat import compat_str
import re import re