mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 07:25:15 +02:00
Merge pull request #1074 from shvaikalesh/improve-named-groups-coverage
Improve named groups coverage
This commit is contained in:
commit
c74e1e4edf
34
test/built-ins/RegExp/named-groups/groups-object.js
Normal file
34
test/built-ins/RegExp/named-groups/groups-object.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// Copyright 2017 Aleksey Shvayka. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Properties of the groups object are created with CreateDataProperty
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
esid: sec-regexpbuiltinexec
|
||||||
|
features: [regexp-named-groups]
|
||||||
|
info: >
|
||||||
|
Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||||
|
24. If R contains any GroupName,
|
||||||
|
a. Let groups be ObjectCreate(null).
|
||||||
|
b. Perform ! CreateDataProperty(A, "groups", groups).
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// groups is created with Define, not Set
|
||||||
|
let counter = 0;
|
||||||
|
Object.defineProperty(Array.prototype, "groups", {set() { counter++; }});
|
||||||
|
let match = /(?<x>.)/.exec("a");
|
||||||
|
assert.sameValue(counter, 0);
|
||||||
|
|
||||||
|
// groups is writable, enumerable and configurable
|
||||||
|
// (from CreateDataProperty)
|
||||||
|
verifyProperty(match, "groups", {
|
||||||
|
writable: true,
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// The '__proto__' property on the groups object is not special,
|
||||||
|
// and does not affect the [[Prototype]] of the resulting groups object.
|
||||||
|
let {groups} = /(?<__proto__>.)/.exec("a");
|
||||||
|
assert.sameValue("a", groups.__proto__);
|
||||||
|
assert.sameValue(null, Object.getPrototypeOf(groups));
|
@ -31,9 +31,3 @@ assert.sameValue(counter, 0);
|
|||||||
verifyWritable(groups, "x");
|
verifyWritable(groups, "x");
|
||||||
verifyEnumerable(groups, "x");
|
verifyEnumerable(groups, "x");
|
||||||
verifyConfigurable(groups, "x");
|
verifyConfigurable(groups, "x");
|
||||||
|
|
||||||
// The '__proto__' property on the groups object is not special,
|
|
||||||
// and does not affect the [[Prototype]] of the resulting groups object.
|
|
||||||
groups = /(?<__proto__>a)/u.exec("a").groups;
|
|
||||||
assert.sameValue("a", groups.__proto__);
|
|
||||||
assert.sameValue(null, Object.getPrototypeOf(groups));
|
|
||||||
|
@ -23,6 +23,7 @@ assert(/\k<a/.test("k<a"));
|
|||||||
assert(/\k/.test("k"));
|
assert(/\k/.test("k"));
|
||||||
assert.throws(SyntaxError, () => eval("/(?<a>.)\\k/"));
|
assert.throws(SyntaxError, () => eval("/(?<a>.)\\k/"));
|
||||||
assert.throws(SyntaxError, () => eval("/(?<a>.)\\k<a/"));
|
assert.throws(SyntaxError, () => eval("/(?<a>.)\\k<a/"));
|
||||||
|
assert.throws(SyntaxError, () => eval("/(?<a>.)\\k<>/"));
|
||||||
assert.throws(SyntaxError, () => eval("/(?<a>.)\\k<b>/"));
|
assert.throws(SyntaxError, () => eval("/(?<a>.)\\k<b>/"));
|
||||||
assert.throws(SyntaxError, () => eval("/(?<a>a)\\k<ab>/"));
|
assert.throws(SyntaxError, () => eval("/(?<a>a)\\k<ab>/"));
|
||||||
assert.throws(SyntaxError, () => eval("/(?<ab>a)\\k<a>/"));
|
assert.throws(SyntaxError, () => eval("/(?<ab>a)\\k<a>/"));
|
||||||
|
24
test/built-ins/RegExp/named-groups/string-replace-escaped.js
Normal file
24
test/built-ins/RegExp/named-groups/string-replace-escaped.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2017 Aleksey Shvayka. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Do not replace $<> preceded with $
|
||||||
|
esid: sec-getsubstitution
|
||||||
|
features: [regexp-named-groups]
|
||||||
|
info: >
|
||||||
|
Runtime Semantics: GetSubstitution( matched, str, position, captures, namedCaptures, replacement )
|
||||||
|
|
||||||
|
12. These $ replacements are done left-to-right, and, once such a replacement is performed,
|
||||||
|
the new replacement text is not subject to further replacements.
|
||||||
|
|
||||||
|
Table: Replacement Text Symbol Substitutions
|
||||||
|
|
||||||
|
Unicode Characters: $$
|
||||||
|
Replacement text: $
|
||||||
|
---*/
|
||||||
|
|
||||||
|
let source = "(?<fst>.)";
|
||||||
|
for (let flags of ["", "u"]) {
|
||||||
|
let re = new RegExp(source, flags);
|
||||||
|
assert.sameValue("$<fst>bc", "abc".replace(re, "$$<fst>"));
|
||||||
|
}
|
@ -21,4 +21,6 @@ for (let flags of ["", "u", "g", "gu"]) {
|
|||||||
let re = new RegExp(source, flags);
|
let re = new RegExp(source, flags);
|
||||||
assert.throws(SyntaxError, () => "abcd".replace(re, "$<snd"),
|
assert.throws(SyntaxError, () => "abcd".replace(re, "$<snd"),
|
||||||
"unclosed named group in replacement should throw a SyntaxError");
|
"unclosed named group in replacement should throw a SyntaxError");
|
||||||
|
assert.throws(SyntaxError, () => "abcd".replace(re, "$<>"),
|
||||||
|
"empty named group in replacement should throw a SyntaxError");
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,11 @@ assert.throws(SyntaxError, () => eval("/(?<a>a)(?<a>a)/u"), "Duplicate name");
|
|||||||
assert.throws(SyntaxError, () => eval("/(?<a>a)(?<b>b)(?<a>a)/u"), "Duplicate name");
|
assert.throws(SyntaxError, () => eval("/(?<a>a)(?<b>b)(?<a>a)/u"), "Duplicate name");
|
||||||
assert.throws(SyntaxError, () => eval("/\\k<a>/u"), "Invalid reference");
|
assert.throws(SyntaxError, () => eval("/\\k<a>/u"), "Invalid reference");
|
||||||
assert.throws(SyntaxError, () => eval("/\\k<a/u"), "Unterminated reference");
|
assert.throws(SyntaxError, () => eval("/\\k<a/u"), "Unterminated reference");
|
||||||
|
assert.throws(SyntaxError, () => eval("/\\k<>/u"), "Empty reference");
|
||||||
assert.throws(SyntaxError, () => eval("/\\k/u"), "Lone \k");
|
assert.throws(SyntaxError, () => eval("/\\k/u"), "Lone \k");
|
||||||
assert.throws(SyntaxError, () => eval("/(?<a>.)\\k/u"), "Lone \k");
|
assert.throws(SyntaxError, () => eval("/(?<a>.)\\k/u"), "Lone \k");
|
||||||
assert.throws(SyntaxError, () => eval("/(?<a>.)\\k<a/u"), "Unterminated reference");
|
assert.throws(SyntaxError, () => eval("/(?<a>.)\\k<a/u"), "Unterminated reference");
|
||||||
|
assert.throws(SyntaxError, () => eval("/(?<a>.)\\k<>/u"), "Empty reference");
|
||||||
assert.throws(SyntaxError, () => eval("/(?<a>.)\\k<b>/u"), "Invalid reference");
|
assert.throws(SyntaxError, () => eval("/(?<a>.)\\k<b>/u"), "Invalid reference");
|
||||||
assert.throws(SyntaxError, () => eval("/(?<a>a)\\k<ab>/u"), "Invalid reference");
|
assert.throws(SyntaxError, () => eval("/(?<a>a)\\k<ab>/u"), "Invalid reference");
|
||||||
assert.throws(SyntaxError, () => eval("/(?<ab>a)\\k<a>/u"), "Invalid reference");
|
assert.throws(SyntaxError, () => eval("/(?<ab>a)\\k<a>/u"), "Invalid reference");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user