diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/String/prototype/match/duplicate-named-groups-properties.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/match/duplicate-named-groups-properties.js')
-rw-r--r-- | js/src/tests/test262/built-ins/String/prototype/match/duplicate-named-groups-properties.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/match/duplicate-named-groups-properties.js b/js/src/tests/test262/built-ins/String/prototype/match/duplicate-named-groups-properties.js new file mode 100644 index 0000000000..5cf6bb7691 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/match/duplicate-named-groups-properties.js @@ -0,0 +1,39 @@ +// |reftest| skip -- regexp-duplicate-named-groups is not supported +// Copyright 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Properties on groups object with duplicate named capture groups +esid: prod-GroupSpecifier +features: [regexp-duplicate-named-groups] +includes: [compareArray.js] +---*/ + +const matcher = /(?:(?<x>a)|(?<y>a)(?<x>b))(?:(?<z>c)|(?<z>d))/; + +const threeMatchResult = "abc".match(matcher); +assert.sameValue(threeMatchResult.groups.x, "b", "group x matches b"); +assert.sameValue(threeMatchResult.groups.y, "a", "group y matches a"); +assert.sameValue(threeMatchResult.groups.z, "c", "group z matches c"); +assert.compareArray( + Object.keys(threeMatchResult.groups), + ["x", "y", "z"], + "Properties of groups are ordered in RegExp source order despite y matching before x in this alternative" +); + +const twoMatchResult = "ad".match(matcher); +assert.sameValue(twoMatchResult.groups.x, "a", "group x matches a"); +assert.sameValue(twoMatchResult.groups.y, undefined, "group y does not match"); +assert.sameValue(twoMatchResult.groups.z, "d", "group z matches d"); +assert.compareArray( + Object.keys(twoMatchResult.groups), + ["x", "y", "z"], + "y is still present on groups object, in the right order, despite not matching" +); + +const iteratedMatcher = /(?:(?:(?<x>a)|(?<x>b)|c)\k<x>){2}/; + +const matchedInPrevIterationResult = "aac".match(iteratedMatcher); +assert.sameValue(matchedInPrevIterationResult.groups.x, undefined, "group x does not match in the last iteration"); + +reportCompare(0, 0); |