aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/test_jsinterp.py
diff options
context:
space:
mode:
authordirkf <[email protected]>2024-12-12 04:13:06 +0000
committerdirkf <[email protected]>2024-12-16 12:38:51 +0000
commit94fd7746084d87a43e34b094c5db1325f91ce053 (patch)
tree4538e3e7186d9b2295c7337b19a0ef81991b9c44 /test/test_jsinterp.py
parent5dee6213edddb5ea00775db6b3b73f8355144485 (diff)
downloadyoutube-dl-94fd7746084d87a43e34b094c5db1325f91ce053.tar.gz
youtube-dl-94fd7746084d87a43e34b094c5db1325f91ce053.zip
[jsinterp] Fix and improve split/join
* improve split/join edge cases * correctly implement regex split (not like re.split)
Diffstat (limited to 'test/test_jsinterp.py')
-rw-r--r--test/test_jsinterp.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py
index 52eaf1ed8..b6e87e9f1 100644
--- a/test/test_jsinterp.py
+++ b/test/test_jsinterp.py
@@ -483,6 +483,13 @@ class TestJSInterpreter(unittest.TestCase):
self._test(jsi, 't-e-s-t', args=[test_input, '-'])
self._test(jsi, '', args=[[], '-'])
+ self._test('function f(){return '
+ '[1, 1.0, "abc", {a: 1}, null, undefined, Infinity, NaN].join()}',
+ '1,1,abc,[object Object],,,Infinity,NaN')
+ self._test('function f(){return '
+ '[1, 1.0, "abc", {a: 1}, null, undefined, Infinity, NaN].join("~")}',
+ '1~1~abc~[object Object]~~~Infinity~NaN')
+
def test_split(self):
test_result = list('test')
tests = [
@@ -496,6 +503,18 @@ class TestJSInterpreter(unittest.TestCase):
self._test(jsi, test_result, args=['t-e-s-t', '-'])
self._test(jsi, [''], args=['', '-'])
self._test(jsi, [], args=['', ''])
+ # RegExp split
+ self._test('function f(){return "test".split(/(?:)/)}',
+ ['t', 'e', 's', 't'])
+ self._test('function f(){return "t-e-s-t".split(/[es-]+/)}',
+ ['t', 't'])
+ # from MDN: surrogate pairs aren't handled: case 1 fails
+ # self._test('function f(){return "😄😄".split(/(?:)/)}',
+ # ['\ud83d', '\ude04', '\ud83d', '\ude04'])
+ # case 2 beats Py3.2: it gets the case 1 result
+ if sys.version_info >= (2, 6) and not ((3, 0) <= sys.version_info < (3, 3)):
+ self._test('function f(){return "😄😄".split(/(?:)/u)}',
+ ['😄', '😄'])
def test_slice(self):
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice()}', [0, 1, 2, 3, 4, 5, 6, 7, 8])