diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py index c4bc0e43b..734b5507a 100644 --- a/test/test_jsinterp.py +++ b/test/test_jsinterp.py @@ -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) diff --git a/test/test_jsinterp_parser.py b/test/test_jsinterp_parser.py index 7fba24d83..a1227e94b 100644 --- a/test/test_jsinterp_parser.py +++ b/test/test_jsinterp_parser.py @@ -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( diff --git a/youtube_dl/jsinterp/jsinterp.py b/youtube_dl/jsinterp/jsinterp.py index e327130e9..9d655ed22 100644 --- a/youtube_dl/jsinterp/jsinterp.py +++ b/youtube_dl/jsinterp/jsinterp.py @@ -1,5 +1,4 @@ from __future__ import unicode_literals -from ..compat import compat_str import re