Duplicate named capture groups: Syntax tests

Parse-time syntax for RegExp literals is already tested. These two files
test runtime RegExp compilation, with respect to duplicate named capture
groups.

See: #3704
This commit is contained in:
Philip Chimento 2022-10-20 15:57:25 -07:00 committed by Ms2ger
parent 29f321a4e9
commit d77d9b2b85
2 changed files with 38 additions and 0 deletions

View File

@ -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");

View File

@ -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");