Skip to content

Commit

Permalink
Duplicate named capture groups: Syntax tests
Browse files Browse the repository at this point in the history
Parse-time syntax for RegExp literals is already tested. These two files
test runtime RegExp compilation, with respect to duplicate named capture
groups.

See: tc39#3704
  • Loading branch information
ptomato committed Oct 27, 2022
1 parent ade328d commit 9ecc654
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-regexp.prototype.compile
description: Runtime parsing of syntax for duplicate named capturing groups
features: [regexp-duplicate-named-groups]
---*/

let r = /[ab]/;

assert.throws(
SyntaxError,
() => r.compile("(?<x>a)(?<x>b)"),
"Duplicate named capturing groups in the same alternative do not parse"
);

let source = "(?<x>a)|(?<x>b)";
r.compile(source);
assert.sameValue(r.source, source, "Duplicate named capturing groups in separate alternatives parse correctly");
18 changes: 18 additions & 0 deletions test/built-ins/RegExp/duplicate-named-capturing-groups-syntax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-regexp-pattern-flags
description: Runtime parsing of syntax for duplicate named capturing groups
features: [regexp-duplicate-named-groups]
---*/

assert.throws(
SyntaxError,
() => new RegExp("(?<x>a)(?<x>b)"),
"Duplicate named capturing groups in the same alternative do not parse"
);

let source = "(?<x>a)|(?<x>b)";
let parsed = new RegExp(source);
assert.sameValue(parsed.source, source, "Duplicate named capturing groups in separate alternatives parse correctly");

0 comments on commit 9ecc654

Please sign in to comment.