about summary refs log tree commit diff
path: root/test
diff options
context:
space:
mode:
authordirkf <fieldhouse@gmx.net>2022-08-26 08:17:54 +0100
committerdirkf <fieldhouse@gmx.net>2022-08-26 08:51:17 +0100
commit4c6fba37650d60acbd32a9f2d6e2468a730d0f1c (patch)
tree85cf8b39b00a531e27ca5055fbacb50291469505 /test
parentd619dd712f63aab1964f8fdde9ceea514a5e581d (diff)
downloadyoutube-dl-4c6fba37650d60acbd32a9f2d6e2468a730d0f1c.tar.gz
youtube-dl-4c6fba37650d60acbd32a9f2d6e2468a730d0f1c.tar.xz
youtube-dl-4c6fba37650d60acbd32a9f2d6e2468a730d0f1c.zip
[jsinterp] Improve try/catch/finally support
Diffstat (limited to 'test')
-rw-r--r--test/test_jsinterp.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py
index 0a97bdbc4..fb4882d00 100644
--- a/test/test_jsinterp.py
+++ b/test/test_jsinterp.py
@@ -74,6 +74,9 @@ class TestJSInterpreter(unittest.TestCase):
         jsi = JSInterpreter('function f(){return 0 ?? 42;}')
         self.assertEqual(jsi.call_function('f'), 0)
 
+        jsi = JSInterpreter('function f(){return "life, the universe and everything" < 42;}')
+        self.assertFalse(jsi.call_function('f'))
+
     def test_array_access(self):
         jsi = JSInterpreter('function f(){var x = [1,2,3]; x[0] = 4; x[0] = 5; x[2.0] = 7; return x;}')
         self.assertEqual(jsi.call_function('f'), [5, 2, 7])
@@ -198,7 +201,6 @@ class TestJSInterpreter(unittest.TestCase):
         ''')
         self.assertEqual(jsi.call_function('x'), 5)
 
-    @unittest.expectedFailure
     def test_finally(self):
         jsi = JSInterpreter('''
         function x() { try{throw 10} finally {return 42} }
@@ -212,7 +214,7 @@ class TestJSInterpreter(unittest.TestCase):
     def test_nested_try(self):
         jsi = JSInterpreter('''
         function x() {try {
-            try{throw 10} finally {throw 42} 
+            try{throw 10} finally {throw 42}
             } catch(e){return 5} }
         ''')
         self.assertEqual(jsi.call_function('x'), 5)
@@ -229,6 +231,14 @@ class TestJSInterpreter(unittest.TestCase):
         ''')
         self.assertEqual(jsi.call_function('x'), 0)
 
+    def test_for_loop_try(self):
+        jsi = JSInterpreter('''
+        function x() {
+            for (i=0; i-10; i++) { try { if (i == 5) throw i} catch {return 10} finally {break} };
+            return 42 }
+        ''')
+        self.assertEqual(jsi.call_function('x'), 42)
+
     def test_literal_list(self):
         jsi = JSInterpreter('''
         function x() { return [1, 2, "asdf", [5, 6, 7]][3] }