aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_jsinterp.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2022-08-14 04:51:54 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2022-08-14 05:12:32 +0530
commit8f53dc44a0cc1c2d98c35740b9293462c080f5d0 (patch)
treeddc64192482cd2af381524415a20a3165e110857 /test/test_jsinterp.py
parent1cddfdc52b39f6760a70869632d12577b080b69c (diff)
downloadhypervideo-pre-8f53dc44a0cc1c2d98c35740b9293462c080f5d0.tar.lz
hypervideo-pre-8f53dc44a0cc1c2d98c35740b9293462c080f5d0.tar.xz
hypervideo-pre-8f53dc44a0cc1c2d98c35740b9293462c080f5d0.zip
[jsinterp] Handle new youtube signature functions
Closes #4635
Diffstat (limited to 'test/test_jsinterp.py')
-rw-r--r--test/test_jsinterp.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py
index 4277cabe0..48e2abcf6 100644
--- a/test/test_jsinterp.py
+++ b/test/test_jsinterp.py
@@ -19,6 +19,9 @@ class TestJSInterpreter(unittest.TestCase):
jsi = JSInterpreter('function x3(){return 42;}')
self.assertEqual(jsi.call_function('x3'), 42)
+ jsi = JSInterpreter('function x3(){42}')
+ self.assertEqual(jsi.call_function('x3'), None)
+
jsi = JSInterpreter('var x5 = function(){return 42;}')
self.assertEqual(jsi.call_function('x5'), 42)
@@ -51,8 +54,11 @@ class TestJSInterpreter(unittest.TestCase):
jsi = JSInterpreter('function f(){return 11 >> 2;}')
self.assertEqual(jsi.call_function('f'), 2)
+ jsi = JSInterpreter('function f(){return []? 2+3: 4;}')
+ self.assertEqual(jsi.call_function('f'), 5)
+
def test_array_access(self):
- jsi = JSInterpreter('function f(){var x = [1,2,3]; x[0] = 4; x[0] = 5; x[2] = 7; return x;}')
+ 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])
def test_parens(self):
@@ -62,6 +68,10 @@ class TestJSInterpreter(unittest.TestCase):
jsi = JSInterpreter('function f(){return (1 + 2) * 3;}')
self.assertEqual(jsi.call_function('f'), 9)
+ def test_quotes(self):
+ jsi = JSInterpreter(R'function f(){return "a\"\\("}')
+ self.assertEqual(jsi.call_function('f'), R'a"\(')
+
def test_assignments(self):
jsi = JSInterpreter('function f(){var x = 20; x = 30 + 1; return x;}')
self.assertEqual(jsi.call_function('f'), 31)
@@ -107,14 +117,15 @@ class TestJSInterpreter(unittest.TestCase):
def test_call(self):
jsi = JSInterpreter('''
function x() { return 2; }
- function y(a) { return x() + a; }
+ function y(a) { return x() + (a?a:0); }
function z() { return y(3); }
''')
self.assertEqual(jsi.call_function('z'), 5)
+ self.assertEqual(jsi.call_function('y'), 2)
def test_for_loop(self):
jsi = JSInterpreter('''
- function x() { a=0; for (i=0; i-10; i++) {a++} a }
+ function x() { a=0; for (i=0; i-10; i++) {a++} return a }
''')
self.assertEqual(jsi.call_function('x'), 10)
@@ -155,19 +166,19 @@ class TestJSInterpreter(unittest.TestCase):
def test_for_loop_continue(self):
jsi = JSInterpreter('''
- function x() { a=0; for (i=0; i-10; i++) { continue; a++ } a }
+ function x() { a=0; for (i=0; i-10; i++) { continue; a++ } return 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 }
+ function x() { a=0; for (i=0; i-10; i++) { break; a++ } return a }
''')
self.assertEqual(jsi.call_function('x'), 0)
def test_literal_list(self):
jsi = JSInterpreter('''
- function x() { [1, 2, "asdf", [5, 6, 7]][3] }
+ function x() { return [1, 2, "asdf", [5, 6, 7]][3] }
''')
self.assertEqual(jsi.call_function('x'), [5, 6, 7])
@@ -177,6 +188,12 @@ class TestJSInterpreter(unittest.TestCase):
''')
self.assertEqual(jsi.call_function('x'), 7)
+ def test_return_function(self):
+ jsi = JSInterpreter('''
+ function x() { return [1, function(){return 1}][1] }
+ ''')
+ self.assertEqual(jsi.call_function('x')([]), 1)
+
if __name__ == '__main__':
unittest.main()