1
0
mirror of https://github.com/tc39/test262.git synced 2025-04-08 19:35:28 +02:00

Duplicate named capture groups: Fix match arrays

Each named capturing group should count as its own parenthesized capturing
group, even if it has the same name as another group. So, some of these
expectations were missing `undefined` array elements for the variant of
the `x` capturing group that didn't match.

In the other expectations, we forgot to take into account that the
backreference is not inside a capturing group, so the group match should
not have doubled letters in it.
This commit is contained in:
Philip Chimento 2022-10-28 16:09:08 -07:00 committed by Ms2ger
parent d77d9b2b85
commit fabb1fd379

@ -8,15 +8,15 @@ features: [regexp-duplicate-named-groups]
includes: [compareArray.js]
---*/
assert.compareArray(["b", "b"], "bab".match(/(?<x>a)|(?<x>b)/));
assert.compareArray(["b", "b"], "bab".match(/(?<x>b)|(?<x>a)/));
assert.compareArray(["b", undefined, "b"], "bab".match(/(?<x>a)|(?<x>b)/));
assert.compareArray(["b", "b", undefined], "bab".match(/(?<x>b)|(?<x>a)/));
assert.compareArray(["aa", "aa", undefined], "aa".match(/(?:(?<x>a)|(?<x>b))\k<x>/));
assert.compareArray(["bb", undefined, "bb"], "bb".match(/(?:(?<x>a)|(?<x>b))\k<x>/));
assert.compareArray(["aa", "a", undefined], "aa".match(/(?:(?<x>a)|(?<x>b))\k<x>/));
assert.compareArray(["bb", undefined, "b"], "bb".match(/(?:(?<x>a)|(?<x>b))\k<x>/));
let matchResult = "aabb".match(/(?:(?:(?<x>a)|(?<x>b))\k<x>){2}/);
assert.compareArray(["aabb", undefined, "bb"], matchResult);
assert.sameValue(matchResult.groups.x, "bb");
assert.compareArray(["aabb", undefined, "b"], matchResult);
assert.sameValue(matchResult.groups.x, "b");
let notMatched = "abab".match(/(?:(?:(?<x>a)|(?<x>b))\k<x>){2}/);
assert.sameValue(notMatched, null);