aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_jsinterp.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2023-02-01 09:39:49 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2023-02-01 09:40:16 +0530
commit8b008d62544b82e24a0ba36c30e8e51855d93419 (patch)
tree8262dfc4a1f3757b2ddb55d8c22e415449ea90e3 /test/test_jsinterp.py
parent83c4970e52839ce8761ec61bd19d549aed7d7920 (diff)
downloadhypervideo-pre-8b008d62544b82e24a0ba36c30e8e51855d93419.tar.lz
hypervideo-pre-8b008d62544b82e24a0ba36c30e8e51855d93419.tar.xz
hypervideo-pre-8b008d62544b82e24a0ba36c30e8e51855d93419.zip
[jsinterp] Support `if` statements
Closes #6131
Diffstat (limited to 'test/test_jsinterp.py')
-rw-r--r--test/test_jsinterp.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py
index 3c4391c4a..e090dc791 100644
--- a/test/test_jsinterp.py
+++ b/test/test_jsinterp.py
@@ -155,6 +155,38 @@ class TestJSInterpreter(unittest.TestCase):
self.assertEqual(jsi.call_function('z'), 5)
self.assertEqual(jsi.call_function('y'), 2)
+ def test_if(self):
+ jsi = JSInterpreter('''
+ function x() {
+ let a = 9;
+ if (0==0) {a++}
+ return a
+ }''')
+ self.assertEqual(jsi.call_function('x'), 10)
+
+ jsi = JSInterpreter('''
+ function x() {
+ if (0==0) {return 10}
+ }''')
+ self.assertEqual(jsi.call_function('x'), 10)
+
+ jsi = JSInterpreter('''
+ function x() {
+ if (0!=0) {return 1}
+ else {return 10}
+ }''')
+ self.assertEqual(jsi.call_function('x'), 10)
+
+ """ # Unsupported
+ jsi = JSInterpreter('''
+ function x() {
+ if (0!=0) {return 1}
+ else if (1==0) {return 2}
+ else {return 10}
+ }''')
+ self.assertEqual(jsi.call_function('x'), 10)
+ """
+
def test_for_loop(self):
jsi = JSInterpreter('''
function x() { a=0; for (i=0; i-10; i++) {a++} return a }