diff options
author | dirkf <[email protected]> | 2024-12-12 00:15:31 +0000 |
---|---|---|
committer | dirkf <[email protected]> | 2024-12-16 12:38:51 +0000 |
commit | 81e64cacf2b8c144ec1e9d3258db792f0eb8443e (patch) | |
tree | 57c76ed55d4a17fa607fc84f279d25fc7b2c2836 /test/test_jsinterp.py | |
parent | c1a03b1ac3a453508b358b6d1bc5d158cc80a0ce (diff) | |
download | youtube-dl-81e64cacf2b8c144ec1e9d3258db792f0eb8443e.tar.gz youtube-dl-81e64cacf2b8c144ec1e9d3258db792f0eb8443e.zip |
[jsinterp] Support multiple indexing (eg a[1][2])
* extend single indexing with improved RE (should probably use/have used _separate_at_paren())
* fix some cases that should have given undefined, not throwing
* standardise RE group names
* support length of objects, like {1: 2, 3: 4, length: 42}
Diffstat (limited to 'test/test_jsinterp.py')
-rw-r--r-- | test/test_jsinterp.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py index 86137d8e5..d2fca2997 100644 --- a/test/test_jsinterp.py +++ b/test/test_jsinterp.py @@ -366,6 +366,16 @@ class TestJSInterpreter(unittest.TestCase): self._test('function f() { let a; return a?.qq; }', JS_Undefined) self._test('function f() { let a = {m1: 42, m2: 0 }; return a?.qq; }', JS_Undefined) + def test_indexing(self): + self._test('function f() { return [1, 2, 3, 4][3]}', 4) + self._test('function f() { return [1, [2, [3, [4]]]][1][1][1][0]}', 4) + self._test('function f() { var o = {1: 2, 3: 4}; return o[3]}', 4) + self._test('function f() { var o = {1: 2, 3: 4}; return o["3"]}', 4) + self._test('function f() { return [1, [2, {3: [4]}]][1][1]["3"][0]}', 4) + self._test('function f() { return [1, 2, 3, 4].length}', 4) + self._test('function f() { var o = {1: 2, 3: 4}; return o.length}', JS_Undefined) + self._test('function f() { var o = {1: 2, 3: 4}; o["length"] = 42; return o.length}', 42) + def test_regex(self): self._test('function f() { let a=/,,[/,913,/](,)}/; }', None) |