aboutsummaryrefslogtreecommitdiff
path: root/test/test_jsinterp.py
diff options
context:
space:
mode:
authordirkf <fieldhouse@gmx.net>2022-08-31 23:22:48 +0100
committerdirkf <fieldhouse@gmx.net>2022-09-01 10:57:12 +0100
commit55c823634db890a328ffc23588fcd6f35d9b3ddf (patch)
tree22d6c4e803eff07cb82a23f9b4b519b10b504b5b /test/test_jsinterp.py
parent4050e10a4c3445c5399239567eb074acb2f65c18 (diff)
downloadyoutube-dl-55c823634db890a328ffc23588fcd6f35d9b3ddf.tar.xz
[jsinterp] Handle new YT players 113ca41c, c57c113c
* add NaN * allow any white-space character for `after_op` * align with yt-dlp f26af78a8ac11d9d617ed31ea5282cfaa5bcbcfa (charcodeAt and bitwise overflow) * allow escaping in regex, fixing player c57c113c
Diffstat (limited to 'test/test_jsinterp.py')
-rw-r--r--test/test_jsinterp.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py
index fb4882d00..5121c8cf8 100644
--- a/test/test_jsinterp.py
+++ b/test/test_jsinterp.py
@@ -136,6 +136,11 @@ class TestJSInterpreter(unittest.TestCase):
def test_builtins(self):
jsi = JSInterpreter('''
+ function x() { return NaN }
+ ''')
+ self.assertTrue(math.isnan(jsi.call_function('x')))
+
+ jsi = JSInterpreter('''
function x() { return new Date('Wednesday 31 December 1969 18:01:26 MDT') - 0; }
''')
self.assertEqual(jsi.call_function('x'), 86000)
@@ -385,6 +390,22 @@ class TestJSInterpreter(unittest.TestCase):
''')
self.assertEqual(jsi.call_function('x').flags & ~re.U, re.I)
+ def test_char_code_at(self):
+ jsi = JSInterpreter('function x(i){return "test".charCodeAt(i)}')
+ self.assertEqual(jsi.call_function('x', 0), 116)
+ self.assertEqual(jsi.call_function('x', 1), 101)
+ self.assertEqual(jsi.call_function('x', 2), 115)
+ self.assertEqual(jsi.call_function('x', 3), 116)
+ self.assertEqual(jsi.call_function('x', 4), None)
+ self.assertEqual(jsi.call_function('x', 'not_a_number'), 116)
+
+ def test_bitwise_operators_overflow(self):
+ jsi = JSInterpreter('function x(){return -524999584 << 5}')
+ self.assertEqual(jsi.call_function('x'), 379882496)
+
+ jsi = JSInterpreter('function x(){return 1236566549 << 5}')
+ self.assertEqual(jsi.call_function('x'), 915423904)
+
if __name__ == '__main__':
unittest.main()