forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Added/updated tests for matchAll #1
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
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,34 @@ | ||
// Copyright (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
description: Compare the values of an iterator with an array of expected values | ||
---*/ | ||
|
||
// Example: | ||
// | ||
// function* numbers() { | ||
// yield 1; | ||
// yield 2; | ||
// yield 3; | ||
// } | ||
// | ||
// compareIterator(numbers(), [ | ||
// v => assert.sameValue(v, 1), | ||
// v => assert.sameValue(v, 2), | ||
// v => assert.sameValue(v, 3), | ||
// ]); | ||
// | ||
assert.compareIterator = function(iter, validators, message) { | ||
message = message || ''; | ||
|
||
var i, result; | ||
for (i = 0; i < validators.length; i++) { | ||
result = iter.next(); | ||
assert(!result.done, 'Expected ' + i + ' values(s). Instead iterator only produced ' + (i - 1) + ' value(s). ' + message); | ||
validators[i](result.value); | ||
} | ||
|
||
result = iter.next(); | ||
assert(result.done, 'Expected only ' + i + ' values(s). Instead iterator produced more. ' + message); | ||
assert.sameValue(result.value, undefined, 'Expected value of `undefined` when iterator completes. ' + message); | ||
} |
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
22 changes: 0 additions & 22 deletions
22
test/built-ins/RegExp/prototype/Symbol.matchAll/get-species-constructor-err.js
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
test/built-ins/RegExp/prototype/Symbol.matchAll/internal-regexp-lastindex-not-zero.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 (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: | | ||
Throws TypeError when internally created RegExp's lastIndex is not 0 | ||
info: | | ||
RegExp.prototype [ @@matchAll ] ( string ) | ||
[...] | ||
3. Return ? MatchAllIterator(R, string). | ||
|
||
MatchAllIterator ( R, O ) | ||
[...] | ||
2. If ? IsRegExp(R) is true, then | ||
[...] | ||
3. Else, | ||
a. Let matcher be RegExpCreate(R, "g"). | ||
b. If ? IsRegExp(matcher) is not true, throw a TypeError exception. | ||
[...] | ||
3. If Get(matcher, "lastIndex") is not 0, throw a TypeError exception. | ||
features: [Symbol.match, Symbol.matchAll] | ||
---*/ | ||
|
||
Object.defineProperty(RegExp.prototype, Symbol.match, { | ||
get() { | ||
this.lastIndex = 1; | ||
return true; | ||
} | ||
}); | ||
|
||
assert.throws(TypeError, function() { | ||
RegExp.prototype[Symbol.matchAll].call({}, ''); | ||
}); |
29 changes: 29 additions & 0 deletions
29
test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-internal-regexp-is-false.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,29 @@ | ||
// Copyright (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: Throws TypeError when internally created RegExp's @@match is false | ||
info: | | ||
RegExp.prototype [ @@matchAll ] ( string ) | ||
[...] | ||
3. Return ? MatchAllIterator(R, string). | ||
|
||
MatchAllIterator ( R, O ) | ||
[...] | ||
2. If ? IsRegExp(R) is true, then | ||
[...] | ||
3. Else, | ||
a. Let matcher be RegExpCreate(R, "g"). | ||
b. If ? IsRegExp(matcher) is not true, throw a TypeError exception. | ||
features: [Symbol.match, Symbol.matchAll] | ||
---*/ | ||
|
||
Object.defineProperty(RegExp.prototype, Symbol.match, { | ||
get() { | ||
return false; | ||
} | ||
}); | ||
|
||
assert.throws(TypeError, function() { | ||
RegExp.prototype[Symbol.matchAll].call({}, ''); | ||
}); |
29 changes: 29 additions & 0 deletions
29
test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-internal-regexp-throws.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,29 @@ | ||
// Copyright (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: Re-throws errors thrown while accessing @@match property | ||
info: | | ||
RegExp.prototype [ @@matchAll ] ( string ) | ||
[...] | ||
3. Return ? MatchAllIterator(R, string). | ||
|
||
MatchAllIterator ( R, O ) | ||
[...] | ||
2. If ? IsRegExp(R) is true, then | ||
[...] | ||
3. Else, | ||
a. Let matcher be RegExpCreate(R, "g"). | ||
b. If ? IsRegExp(matcher) is not true, throw a TypeError exception. | ||
features: [Symbol.match, Symbol.matchAll] | ||
---*/ | ||
|
||
Object.defineProperty(RegExp.prototype, Symbol.match, { | ||
get() { | ||
throw new Test262Error(); | ||
} | ||
}); | ||
|
||
assert.throws(Test262Error, function() { | ||
RegExp.prototype[Symbol.matchAll].call({}, ''); | ||
}); |
26 changes: 26 additions & 0 deletions
26
test/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-this-throws.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,26 @@ | ||
// Copyright (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: Re-throws errors thrown while accessing RegExp's @@match property | ||
info: | | ||
RegExp.prototype [ @@matchAll ] ( string ) | ||
[...] | ||
3. Return ? MatchAllIterator(R, string). | ||
|
||
MatchAllIterator ( R, O ) | ||
[...] | ||
2. If ? IsRegExp(R) is true, then | ||
[...] | ||
features: [Symbol.match, Symbol.matchAll] | ||
---*/ | ||
|
||
var obj = { | ||
get [Symbol.match]() { | ||
throw new Test262Error(); | ||
} | ||
}; | ||
|
||
assert.throws(Test262Error, function() { | ||
RegExp.prototype[Symbol.matchAll].call(obj, ''); | ||
}); |
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
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
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
29 changes: 29 additions & 0 deletions
29
test/built-ins/RegExp/prototype/Symbol.matchAll/regexpcreate-this-throws.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,29 @@ | ||
// Copyright (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: Re-throws errors while creating an internal RegExp | ||
info: | | ||
RegExp.prototype [ @@matchAll ] ( string ) | ||
[...] | ||
3. Return ? MatchAllIterator(R, string). | ||
|
||
MatchAllIterator ( R, O ) | ||
[...] | ||
2. If ? IsRegExp(R) is true, then | ||
[...] | ||
3. Else, | ||
a. Let R be RegExpCreate(R, "g"). | ||
features: [Symbol.matchAll] | ||
---*/ | ||
|
||
var obj = { | ||
toString() { | ||
throw new Test262Error(); | ||
} | ||
}; | ||
|
||
assert.throws(Test262Error, function() { | ||
RegExp.prototype[Symbol.matchAll].call(obj, ''); | ||
}); | ||
|
32 changes: 32 additions & 0 deletions
32
.../built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-get-constructor-throws.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,32 @@ | ||
// Copyright (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: | | ||
Re-throws errors thrown while accessing RegExp's constructor property | ||
info: | | ||
RegExp.prototype [ @@matchAll ] ( string ) | ||
[...] | ||
3. Return ? MatchAllIterator(R, string). | ||
|
||
MatchAllIterator ( R, O ) | ||
[...] | ||
2. If ? IsRegExp(R) is true, then | ||
a. Let C be ? SpeciesConstructor(R, RegExp). | ||
|
||
SpeciesConstructor ( O, defaultConstructor ) | ||
[...] | ||
2. Let C be ? Get(O, "constructor"). | ||
features: [Symbol.matchAll] | ||
---*/ | ||
|
||
var regexp = /./; | ||
Object.defineProperty(regexp, 'constructor', { | ||
get(){ | ||
throw new Test262Error(); | ||
} | ||
}); | ||
|
||
assert.throws(Test262Error, function() { | ||
regexp[Symbol.matchAll](''); | ||
}); |
31 changes: 31 additions & 0 deletions
31
test/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-get-species-throws.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,31 @@ | ||
// Copyright (C) 2018 Peter Wong. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: Re-throws errors thrown while accessing of @@species property | ||
info: | | ||
RegExp.prototype [ @@matchAll ] ( string ) | ||
[...] | ||
3. Return ? MatchAllIterator(R, string). | ||
|
||
MatchAllIterator ( R, O ) | ||
[...] | ||
2. If ? IsRegExp(R) is true, then | ||
a. Let C be ? SpeciesConstructor(R, RegExp). | ||
|
||
SpeciesConstructor ( O, defaultConstructor ) | ||
[...] | ||
2. Let C be ? Get(O, "constructor"). | ||
features: [Symbol.matchAll, Symbol.species] | ||
---*/ | ||
|
||
var regexp = /./; | ||
regexp.constructor = { | ||
get [Symbol.species]() { | ||
throw new Test262Error(); | ||
} | ||
}; | ||
|
||
assert.throws(Test262Error, function() { | ||
regexp[Symbol.matchAll](''); | ||
}); |
Oops, something went wrong.
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.
This should also take an
expectedGroups
argument, sincematch
will either lack agroups
property, or have one that's a null object when named capture group syntax is used.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.
I've rebased your branch and am going to merge it; so we can do that in a followup.