mirror of https://github.com/tc39/test262.git
add tests for proposal-duplicate-named-capturing-groups
This commit is contained in:
parent
b42d184876
commit
52284ba4bb
|
@ -276,6 +276,10 @@ regexp-v-flag
|
|||
# https://github.com/tc39/proposal-decorators
|
||||
decorators
|
||||
|
||||
# Duplicate named capturing groups
|
||||
# https://github.com/tc39/proposal-duplicate-named-capturing-groups
|
||||
regexp-duplicate-named-groups
|
||||
|
||||
## Standard language features
|
||||
#
|
||||
# Language features that have been included in a published version of the
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright 2022 Kevin Gibbons. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Enumeration order of the groups object with duplicate named capture groups
|
||||
esid: prod-GroupSpecifier
|
||||
features: [regexp-duplicate-named-groups]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
|
||||
let regexp = /(?<y>a)(?<x>a)|(?<x>b)(?<y>b)/;
|
||||
|
||||
assert.compareArray(
|
||||
Object.keys(regexp.exec("aa").groups),
|
||||
["y", "x"],
|
||||
"property enumeration order of the groups object is based on source order, not match order"
|
||||
);
|
||||
|
||||
assert.compareArray(
|
||||
Object.keys(regexp.exec("bb").groups),
|
||||
["y", "x"],
|
||||
"property enumeration order of the groups object is based on source order, not match order"
|
||||
);
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2022 Kevin Gibbons. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: match indices with duplicate named capture groups
|
||||
esid: sec-makematchindicesindexpairarray
|
||||
features: [regexp-duplicate-named-groups, regexp-match-indices]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
let indices = "..ab".match(/(?<x>a)|(?<x>b)/d).indices;
|
||||
assert.compareArray(indices.groups.x, [2, 3]);
|
||||
|
||||
indices = "..ba".match(/(?<x>a)|(?<x>b)/d).indices;
|
||||
assert.compareArray(indices.groups.x, [2, 3]);
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2022 Kevin Gibbons. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: String.prototype.replace behavior with duplicate named capture groups
|
||||
esid: prod-GroupSpecifier
|
||||
features: [regexp-duplicate-named-groups]
|
||||
---*/
|
||||
|
||||
assert.sameValue("ab".replace(/(?<x>a)|(?<x>b)/, "[$<x>]"), "[a]b");
|
||||
assert.sameValue("ba".replace(/(?<x>a)|(?<x>b)/, "[$<x>]"), "[b]a");
|
||||
|
||||
assert.sameValue("ab".replace(/(?<x>a)|(?<x>b)/, "[$<x>][$1][$2]"), "[a][a][]b");
|
||||
assert.sameValue("ba".replace(/(?<x>a)|(?<x>b)/, "[$<x>][$1][$2]"), "[b][][b]a");
|
||||
|
||||
assert.sameValue("ab".replace(/(?<x>a)|(?<x>b)/g, "[$<x>]"), "[a][b]");
|
||||
assert.sameValue("ba".replace(/(?<x>a)|(?<x>b)/g, "[$<x>]"), "[b][a]");
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright 2022 Kevin Gibbons. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Matching behavior with duplicate named capture groups
|
||||
esid: prod-GroupSpecifier
|
||||
features: [regexp-duplicate-named-groups]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
assert.compareArray(["b", "b"], "bab".match(/(?<x>a)|(?<x>b)/));
|
||||
assert.compareArray(["b", "b"], "bab".match(/(?<x>b)|(?<x>a)/));
|
||||
|
||||
assert.compareArray(["aa", "aa", undefined], "aa".match(/(?:(?<x>a)|(?<x>b))\k<x>/));
|
||||
assert.compareArray(["bb", undefined, "bb"], "bb".match(/(?:(?<x>a)|(?<x>b))\k<x>/));
|
||||
|
||||
let matchResult = "aabb".match(/(?:(?:(?<x>a)|(?<x>b))\k<x>){2}/);
|
||||
assert.compareArray(["aabb", undefined, "bb"], matchResult);
|
||||
assert.sameValue(matchResult.groups.x, "bb");
|
Loading…
Reference in New Issue