From 9ecc654b77e360430671f2c054c8caa2be691f1b Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 20 Oct 2022 15:57:25 -0700 Subject: [PATCH] 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 --- ...duplicate-named-capturing-groups-syntax.js | 20 +++++++++++++++++++ ...duplicate-named-capturing-groups-syntax.js | 18 +++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/annexB/built-ins/RegExp/prototype/compile/duplicate-named-capturing-groups-syntax.js create mode 100644 test/built-ins/RegExp/duplicate-named-capturing-groups-syntax.js diff --git a/test/annexB/built-ins/RegExp/prototype/compile/duplicate-named-capturing-groups-syntax.js b/test/annexB/built-ins/RegExp/prototype/compile/duplicate-named-capturing-groups-syntax.js new file mode 100644 index 00000000000..c499bd2a153 --- /dev/null +++ b/test/annexB/built-ins/RegExp/prototype/compile/duplicate-named-capturing-groups-syntax.js @@ -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("(?a)(?b)"), + "Duplicate named capturing groups in the same alternative do not parse" +); + +let source = "(?a)|(?b)"; +r.compile(source); +assert.sameValue(r.source, source, "Duplicate named capturing groups in separate alternatives parse correctly"); diff --git a/test/built-ins/RegExp/duplicate-named-capturing-groups-syntax.js b/test/built-ins/RegExp/duplicate-named-capturing-groups-syntax.js new file mode 100644 index 00000000000..8d649462e2a --- /dev/null +++ b/test/built-ins/RegExp/duplicate-named-capturing-groups-syntax.js @@ -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("(?a)(?b)"), + "Duplicate named capturing groups in the same alternative do not parse" +); + +let source = "(?a)|(?b)"; +let parsed = new RegExp(source); +assert.sameValue(parsed.source, source, "Duplicate named capturing groups in separate alternatives parse correctly");