[jsinterp] Adding code to if and switch test
This commit is contained in:
parent
ad49621758
commit
c2e6ca5432
@ -45,6 +45,8 @@ class TestJSInterpreter(unittest.TestCase):
|
||||
jsi = JSInterpreter('function $_xY1 ($_axY1) { var $_axY2 = $_axY1 + 1; return $_axY2; }')
|
||||
self.assertEqual(jsi.call_function('$_xY1', 20), 21)
|
||||
|
||||
# TODO test prefix and postfix operators
|
||||
|
||||
def test_operators(self):
|
||||
jsi = JSInterpreter('function f(){return 1 << 5;}')
|
||||
self.assertEqual(jsi.call_function('f'), 32)
|
||||
|
@ -630,13 +630,79 @@ class TestJSInterpreterParser(unittest.TestCase):
|
||||
]
|
||||
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):
|
||||
# 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('')
|
||||
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):
|
||||
# https://hg.mozilla.org/mozilla-central/file/tip/js/src/tests/ecma_5/Array/unshift-01.js
|
||||
jsi = JSInterpreter(
|
||||
|
@ -1,5 +1,4 @@
|
||||
from __future__ import unicode_literals
|
||||
from ..compat import compat_str
|
||||
|
||||
import re
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user