-
Notifications
You must be signed in to change notification settings - Fork 475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[regexp-named-groups] Expand tests for groups
property
#1376
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
test/built-ins/RegExp/named-groups/groups-object-subclass-sans.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,37 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: > | ||
Test the groups object on RegExp subclass results that do not have their own. | ||
includes: [propertyHelper.js] | ||
esid: sec-regexpbuiltinexec | ||
features: [regexp-named-groups] | ||
info: > | ||
Runtime Semantics: RegExpBuiltinExec ( R, S ) | ||
24. If _R_ contains any |GroupName|, then | ||
a. Let _groups_ be ObjectCreate(*null*). | ||
25. Else, | ||
a. Let _groups_ be *undefined*. | ||
26. Perform ! CreateDataProperty(_A_, `"groups"`, _groups_). | ||
---*/ | ||
|
||
class FakeRegExp extends RegExp { | ||
exec(subject) { | ||
const fakeResult = ["ab", "a"]; | ||
fakeResult.index = 0; | ||
// `groups` is not set, triggering prototype lookup. | ||
return fakeResult; | ||
} | ||
}; | ||
|
||
const re = new FakeRegExp(); | ||
const result = re.exec("ab"); | ||
assert.sameValue(result.__proto__, Array.prototype); | ||
assert.sameValue(false, result.hasOwnProperty("groups")); | ||
|
||
Array.prototype.groups = { a: "b" }; | ||
Array.prototype.groups.__proto__.b = "c"; | ||
assert.sameValue("b", "ab".replace(re, "$<a>")); | ||
assert.sameValue("c", "ab".replace(re, "$<b>")); | ||
Array.prototype.groups = undefined; |
35 changes: 35 additions & 0 deletions
35
test/built-ins/RegExp/named-groups/groups-object-subclass.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,35 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: > | ||
Test the groups object on RegExp subclass results that have their own. | ||
includes: [propertyHelper.js] | ||
esid: sec-regexpbuiltinexec | ||
features: [regexp-named-groups] | ||
info: > | ||
Runtime Semantics: RegExpBuiltinExec ( R, S ) | ||
24. If _R_ contains any |GroupName|, then | ||
a. Let _groups_ be ObjectCreate(*null*). | ||
25. Else, | ||
a. Let _groups_ be *undefined*. | ||
26. Perform ! CreateDataProperty(_A_, `"groups"`, _groups_). | ||
---*/ | ||
|
||
class FakeRegExp extends RegExp { | ||
exec(subject) { | ||
const fakeResult = ["ab", "a"]; | ||
fakeResult.index = 0; | ||
fakeResult.groups = { a: "b" }; | ||
fakeResult.groups.__proto__.b = "c"; | ||
return fakeResult; | ||
} | ||
}; | ||
|
||
const re = new FakeRegExp(); | ||
const result = re.exec("ab"); | ||
assert.sameValue(result.__proto__, Array.prototype); | ||
assert(result.hasOwnProperty("groups")); | ||
assert.sameValue("b", result.groups.a); | ||
assert.sameValue("b", "ab".replace(re, "$<a>")); | ||
assert.sameValue("c", "ab".replace(re, "$<b>")); |
33 changes: 33 additions & 0 deletions
33
test/built-ins/RegExp/named-groups/groups-object-undefined.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,33 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: The groups object is created unconditionally. | ||
includes: [propertyHelper.js] | ||
esid: sec-regexpbuiltinexec | ||
features: [regexp-named-groups] | ||
info: > | ||
Runtime Semantics: RegExpBuiltinExec ( R, S ) | ||
24. If _R_ contains any |GroupName|, then | ||
a. Let _groups_ be ObjectCreate(*null*). | ||
25. Else, | ||
a. Let _groups_ be *undefined*. | ||
26. Perform ! CreateDataProperty(_A_, `"groups"`, _groups_). | ||
---*/ | ||
|
||
const re = /./; | ||
const result = re.exec("a"); | ||
assert.sameValue(result.__proto__, Array.prototype); | ||
assert(result.hasOwnProperty("groups")); | ||
assert.sameValue("a", result[0]); | ||
assert.sameValue(0, result.index); | ||
assert.sameValue(undefined, result.groups); | ||
verifyProperty(result, "groups", { | ||
writable: true, | ||
enumerable: true, | ||
configurable: true, | ||
}); | ||
|
||
Array.prototype.groups = { a: "b" }; | ||
assert.sameValue("$<a>", "a".replace(re, "$<a>")); | ||
Array.prototype.groups = undefined; |
36 changes: 36 additions & 0 deletions
36
test/built-ins/RegExp/named-groups/groups-object-unmatched.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,36 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: > | ||
Test the groups object with matched and unmatched named captures. | ||
includes: [propertyHelper.js] | ||
esid: sec-regexpbuiltinexec | ||
features: [regexp-named-groups] | ||
info: > | ||
Runtime Semantics: RegExpBuiltinExec ( R, S ) | ||
24. If _R_ contains any |GroupName|, then | ||
a. Let _groups_ be ObjectCreate(*null*). | ||
25. Else, | ||
a. Let _groups_ be *undefined*. | ||
26. Perform ! CreateDataProperty(_A_, `"groups"`, _groups_). | ||
---*/ | ||
|
||
const re = /(?<a>a).|(?<x>x)/; | ||
const result = re.exec("ab"); | ||
assert.sameValue(result.__proto__, Array.prototype); | ||
assert(result.hasOwnProperty("groups")); | ||
assert.sameValue("ab", result[0]); | ||
assert.sameValue("a", result[1]); | ||
assert.sameValue(undefined, result[2]); | ||
assert.sameValue(0, result.index); | ||
assert.sameValue("a", result.groups.a); | ||
assert.sameValue(undefined, result.groups.x); | ||
|
||
// `a` is a matched named capture, `b` is an unmatched named capture, and `z` | ||
// is not a named capture. | ||
Array.prototype.groups = { a: "b", x: "y", z: "z" }; | ||
assert.sameValue("a", "ab".replace(re, "$<a>")); | ||
assert.sameValue("", "ab".replace(re, "$<x>")); | ||
assert.sameValue("", "ab".replace(re, "$<z>")); | ||
Array.prototype.groups = undefined; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3