aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_jsinterp.py
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2021-11-27 13:25:01 -0500
committerJesús <heckyel@hyperbola.info>2021-11-27 13:25:01 -0500
commitc6df1db4745c9d399204876bbe04e8a311c01df1 (patch)
treea9f4ffa1db45e367aba1de858ac536b761f192fb /test/test_jsinterp.py
parent5bb25093eb718346ab8a723d2c04f0066fc3958a (diff)
parent93e597ba287539643851f0ad5c5ff04760380268 (diff)
downloadhypervideo-pre-c6df1db4745c9d399204876bbe04e8a311c01df1.tar.lz
hypervideo-pre-c6df1db4745c9d399204876bbe04e8a311c01df1.tar.xz
hypervideo-pre-c6df1db4745c9d399204876bbe04e8a311c01df1.zip
updated from upstream | 27/11/2021 at 13:25
Diffstat (limited to 'test/test_jsinterp.py')
-rw-r--r--test/test_jsinterp.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py
index 8b2b60403..e230b045f 100644
--- a/test/test_jsinterp.py
+++ b/test/test_jsinterp.py
@@ -112,6 +112,71 @@ class TestJSInterpreter(unittest.TestCase):
''')
self.assertEqual(jsi.call_function('z'), 5)
+ def test_for_loop(self):
+ jsi = JSInterpreter('''
+ function x() { a=0; for (i=0; i-10; i++) {a++} a }
+ ''')
+ self.assertEqual(jsi.call_function('x'), 10)
+
+ def test_switch(self):
+ jsi = JSInterpreter('''
+ function x(f) { switch(f){
+ case 1:f+=1;
+ case 2:f+=2;
+ case 3:f+=3;break;
+ case 4:f+=4;
+ default:f=0;
+ } return f }
+ ''')
+ self.assertEqual(jsi.call_function('x', 1), 7)
+ self.assertEqual(jsi.call_function('x', 3), 6)
+ self.assertEqual(jsi.call_function('x', 5), 0)
+
+ def test_switch_default(self):
+ jsi = JSInterpreter('''
+ function x(f) { switch(f){
+ case 2: f+=2;
+ default: f-=1;
+ case 5:
+ case 6: f+=6;
+ case 0: break;
+ case 1: f+=1;
+ } return f }
+ ''')
+ self.assertEqual(jsi.call_function('x', 1), 2)
+ self.assertEqual(jsi.call_function('x', 5), 11)
+ self.assertEqual(jsi.call_function('x', 9), 14)
+
+ def test_try(self):
+ jsi = JSInterpreter('''
+ function x() { try{return 10} catch(e){return 5} }
+ ''')
+ self.assertEqual(jsi.call_function('x'), 10)
+
+ def test_for_loop_continue(self):
+ jsi = JSInterpreter('''
+ function x() { a=0; for (i=0; i-10; i++) { continue; a++ } a }
+ ''')
+ self.assertEqual(jsi.call_function('x'), 0)
+
+ def test_for_loop_break(self):
+ jsi = JSInterpreter('''
+ function x() { a=0; for (i=0; i-10; i++) { break; a++ } a }
+ ''')
+ self.assertEqual(jsi.call_function('x'), 0)
+
+ def test_literal_list(self):
+ jsi = JSInterpreter('''
+ function x() { [1, 2, "asdf", [5, 6, 7]][3] }
+ ''')
+ self.assertEqual(jsi.call_function('x'), [5, 6, 7])
+
+ def test_comma(self):
+ jsi = JSInterpreter('''
+ function x() { a=5; a -= 1, a+=3; return a }
+ ''')
+ self.assertEqual(jsi.call_function('x'), 7)
+
if __name__ == '__main__':
unittest.main()