Skip to content

Commit

Permalink
Duplicate named capture groups: Fix match arrays
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ptomato authored and Ms2ger committed Nov 2, 2022
1 parent d77d9b2 commit fabb1fd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions test/built-ins/RegExp/named-groups/duplicate-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit fabb1fd

Please sign in to comment.