forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: tc39#3704
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
test/annexB/built-ins/RegExp/prototype/compile/duplicate-named-capturing-groups-syntax.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
test/built-ins/RegExp/duplicate-named-capturing-groups-syntax.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |