about summary refs log tree commit diff
path: root/test/test_jsinterp.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2023-02-01 09:39:49 +0530
committerdirkf <fieldhouse@gmx.net>2023-02-02 13:12:46 +0000
commit14ef89a8dab4f6ba6185d6f5bf0317a705d7b842 (patch)
treeb4f9140669fcd8b0646da04b088573def7fc45c3 /test/test_jsinterp.py
parent195f22f679330549882a8234e7234942893a4902 (diff)
downloadyoutube-dl-14ef89a8dab4f6ba6185d6f5bf0317a705d7b842.tar.gz
youtube-dl-14ef89a8dab4f6ba6185d6f5bf0317a705d7b842.tar.xz
youtube-dl-14ef89a8dab4f6ba6185d6f5bf0317a705d7b842.zip
Support `if` statements
Fix for yt-dlp/yt_dlp#6131
Closes #31509
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 5121c8cf8..c47def737 100644
--- a/test/test_jsinterp.py
+++ b/test/test_jsinterp.py
@@ -158,6 +158,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):
         # function x() { a=0; for (i=0; i-10; i++) {a++} a }
         jsi = JSInterpreter('''