Debian Codegraph @

js/src/tests/test262/built-ins/RegExp/named-groups/duplicate-names-exec.js

raw
1 // |reftest| shell-option(--enable-regexp-duplicate-named-groups) skip-if(!xulRuntime.shell) -- requires shell-options
2 // Copyright 2022 Igalia S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 description: Matching behavior with duplicate named capture groups
7 esid: prod-GroupSpecifier
8 features: [regexp-duplicate-named-groups]
9 includes: [compareArray.js]
10 ---*/
11
12 assert.compareArray(/(?<x>a)|(?<x>b)/.exec("bab"), ["b", undefined, "b"]);
13 assert.compareArray(/(?<x>b)|(?<x>a)/.exec("bab"), ["b", "b", undefined]);
14
15 assert.compareArray(/(?:(?<x>a)|(?<x>b))\k<x>/.exec("aa"), ["aa", "a", undefined]);
16 assert.compareArray(/(?:(?<x>a)|(?<x>b))\k<x>/.exec("bb"), ["bb", undefined, "b"]);
17
18 let matchResult = /(?:(?:(?<x>a)|(?<x>b))\k<x>){2}/.exec("aabb");
19 assert.compareArray(matchResult, ["aabb", undefined, "b"]);
20 assert.sameValue(matchResult.groups.x, "b");
21
22 assert.sameValue(/(?:(?:(?<x>a)|(?<x>b))\k<x>){2}/.exec("abab"), null);
23
24 assert.sameValue(/(?:(?<x>a)|(?<x>b))\k<x>/.exec("abab"), null);
25
26 assert.sameValue(/(?:(?<x>a)|(?<x>b))\k<x>/.exec("cdef"), null);
27
28 assert.compareArray(/^(?:(?<a>x)|(?<a>y)|z)\k<a>$/.exec("xx"), ["xx", "x", undefined]);
29 assert.compareArray(/^(?:(?<a>x)|(?<a>y)|z)\k<a>$/.exec("z"), ["z", undefined, undefined]);
30 assert.sameValue(/^(?:(?<a>x)|(?<a>y)|z)\k<a>$/.exec("zz"), null);
31 assert.compareArray(/(?<a>x)|(?:zy\k<a>)/.exec("zy"), ["zy", undefined]);
32
33 assert.compareArray(/^(?:(?<a>x)|(?<a>y)|z){2}\k<a>$/.exec("xz"), ["xz", undefined, undefined]);
34 assert.compareArray(/^(?:(?<a>x)|(?<a>y)|z){2}\k<a>$/.exec("yz"), ["yz", undefined, undefined]);
35 assert.sameValue(/^(?:(?<a>x)|(?<a>y)|z){2}\k<a>$/.exec("xzx"), null);
36 assert.sameValue(/^(?:(?<a>x)|(?<a>y)|z){2}\k<a>$/.exec("yzy"), null);
37
38 reportCompare(0, 0);