about summary refs log tree commit diff
path: root/test
diff options
context:
space:
mode:
authordirkf <fieldhouse@gmx.net>2023-05-11 20:59:30 +0100
committerdirkf <fieldhouse@gmx.net>2023-05-11 20:59:30 +0100
commita85a875fef2e9b097c3f6f93f1d0cead06f84e43 (patch)
tree4bfa20eb5c64e8e7c8f3435987f9d57c43170074 /test
parent11cc3f3ad03a88d6cb1eab18a8e5dd6bf148ac54 (diff)
downloadyoutube-dl-a85a875fef2e9b097c3f6f93f1d0cead06f84e43.tar.gz
youtube-dl-a85a875fef2e9b097c3f6f93f1d0cead06f84e43.tar.xz
youtube-dl-a85a875fef2e9b097c3f6f93f1d0cead06f84e43.zip
[jsinterp] Handle NaN in bitwise operators
* also add _NaN
* also pull function naming from yt-dlp
Diffstat (limited to 'test')
-rw-r--r--test/test_jsinterp.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py
index e121358d7..a8f312fde 100644
--- a/test/test_jsinterp.py
+++ b/test/test_jsinterp.py
@@ -18,6 +18,7 @@ class TestJSInterpreter(unittest.TestCase):
     def test_basic(self):
         jsi = JSInterpreter('function x(){;}')
         self.assertEqual(jsi.call_function('x'), None)
+        self.assertEqual(repr(jsi.extract_function('x')), 'F<x>')
 
         jsi = JSInterpreter('function x3(){return 42;}')
         self.assertEqual(jsi.call_function('x3'), 42)
@@ -505,6 +506,16 @@ class TestJSInterpreter(unittest.TestCase):
         jsi = JSInterpreter('function x(){return 1236566549 << 5}')
         self.assertEqual(jsi.call_function('x'), 915423904)
 
+    def test_bitwise_operators_madness(self):
+        jsi = JSInterpreter('function x(){return null << 5}')
+        self.assertEqual(jsi.call_function('x'), 0)
+
+        jsi = JSInterpreter('function x(){return undefined >> 5}')
+        self.assertEqual(jsi.call_function('x'), 0)
+
+        jsi = JSInterpreter('function x(){return 42 << NaN}')
+        self.assertEqual(jsi.call_function('x'), 42)
+
     def test_32066(self):
         jsi = JSInterpreter("function x(){return Math.pow(3, 5) + new Date('1970-01-01T08:01:42.000+08:00') / 1000 * -239 - -24205;}")
         self.assertEqual(jsi.call_function('x'), 70)