diff options
author | Simon Sawicki <contact@grub4k.xyz> | 2025-02-08 18:48:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-08 18:48:36 +0100 |
commit | 0d9f061d38c3a4da61972e2adad317079f2f1c84 (patch) | |
tree | 0ff1a9086dafda40ee62013aed2d19cd58017218 /test/test_jsinterp.py | |
parent | 517ddf3c3f12560ab93e3d36244dc82db9f97818 (diff) |
[jsinterp] Add `js_number_to_string` (#12110)
Authored by: Grub4K
Diffstat (limited to 'test/test_jsinterp.py')
-rw-r--r-- | test/test_jsinterp.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py index 06840ed85..c1464f2cd 100644 --- a/test/test_jsinterp.py +++ b/test/test_jsinterp.py @@ -9,7 +9,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import math -from yt_dlp.jsinterp import JS_Undefined, JSInterpreter +from yt_dlp.jsinterp import JS_Undefined, JSInterpreter, js_number_to_string class NaN: @@ -431,6 +431,27 @@ class TestJSInterpreter(unittest.TestCase): self._test('function f(){return "012345678".slice(-1, 1)}', '') self._test('function f(){return "012345678".slice(-3, -1)}', '67') + def test_js_number_to_string(self): + for test, radix, expected in [ + (0, None, '0'), + (-0, None, '0'), + (0.0, None, '0'), + (-0.0, None, '0'), + (math.nan, None, 'NaN'), + (-math.nan, None, 'NaN'), + (math.inf, None, 'Infinity'), + (-math.inf, None, '-Infinity'), + (10 ** 21.5, 8, '526665530627250154000000'), + (6, 2, '110'), + (254, 16, 'fe'), + (-10, 2, '-1010'), + (-0xff, 2, '-11111111'), + (0.1 + 0.2, 16, '0.4cccccccccccd'), + (1234.1234, 10, '1234.1234'), + # (1000000000000000128, 10, '1000000000000000100') + ]: + assert js_number_to_string(test, radix) == expected + if __name__ == '__main__': unittest.main() |