Conversation
…matchall], and %RegExpStringIteratorPrototype% Tests were updated and assuming tc39/proposal-string-matchall#33 will be merged.
| @@ -1,22 +0,0 @@ | |||
| // Copyright (C) 2015 the V8 project authors. All rights reserved. | |||
There was a problem hiding this comment.
This test is now: species-constructor-get-species-throws.js
| @@ -1,36 +0,0 @@ | |||
| // Copyright (C) 2018 Jordan Harband. All rights reserved. | |||
| @@ -1,22 +0,0 @@ | |||
| // Copyright (C) 2018 Jordan Harband. All rights reserved. | |||
There was a problem hiding this comment.
This test is now: isregexp-internal-regexp-is-false.js
| @@ -1,26 +0,0 @@ | |||
| // Copyright (C) 2018 Jordan Harband. All rights reserved. | |||
There was a problem hiding this comment.
This test is now:
| @@ -1,43 +0,0 @@ | |||
| // Copyright (C) 2018 Jordan Harband. All rights reserved. | |||
There was a problem hiding this comment.
This test was removed as per changes from tc39/proposal-string-matchall#33
- Given a string, @@matchall is no longer executed on the internally created
RegExp.
ljharb
left a comment
There was a problem hiding this comment.
Thanks, this is amazing!
Definitely please use var and normal functions (and no destructuring); these tests should work in a fully polyfilled ES5 implementation as much as they can.
| RegExp.prototype[Symbol.matchAll].call({}, ''); | ||
| }); | ||
| } finally { | ||
| Object.defineProperty(RegExp.prototype, Symbol.match, { |
There was a problem hiding this comment.
Tests generally don’t need to clean up after themselves; each test is run in its own environment.
|
|
||
| assert.sameValue(RegExpStringIteratorProto.next.length, 0); | ||
|
|
||
| verifyNotEnumerable(RegExpStringIteratorProto.next, "length"); |
There was a problem hiding this comment.
We should try to use consistent quotes in this pr; probably single over double?
| const str = 'a*b'; | ||
| const iter = regexp[Symbol.matchAll](str); | ||
|
|
||
| let { value, done } = iter.next(); |
There was a problem hiding this comment.
We should probably make a helper for working with iterator so; maybe giving it the iterator and an array of expected values (or an array of functions to test each value), and have it test everything? Seems like it would DRY up a lot of these tests.
There was a problem hiding this comment.
Yeah, sounds good to me. Is the following kinda what you had in mind?
// harness/compareIterator.js
assert.compareIterator = function compareIterator(iter, validators) {
var i = 0;
var result = iter.next();
while (result.done !== false) {
validators[i](result.value);
result = iter.next();
i++;
}
}
// harness/regExpUtils.js
function matchComparator(expectedEntries, expectedIndex, expectedInput) {
return function(match) {
assert.compareArray(match, expectedEntries);
assert.sameValue(match.index, expectedIndex);
assert.sameValue(match.input, expectedInput);
}
}
// Example usage
assert.compareIterator(regexp[Symbol.matchAll](str), [
matchComparator(['a'], 0, str),
matchComparator(['b'], 2, str)
]);There was a problem hiding this comment.
Yes, that looks great! Perhaps also with something that fails if the iterator is not "done" precisely after validators.length iterations?
There was a problem hiding this comment.
Ah yes! I have implemented and applied the helpers (with your suggested "done" check) in the latest commit: 74aac5b
|
@ljharb I believe I've addressed your initial round of review comments:
... and am ready for another round of review! |
| return function(match) { | ||
| assert.compareArray(match, expectedEntries, 'Match entries'); | ||
| assert.sameValue(match.index, expectedIndex, 'Match index'); | ||
| assert.sameValue(match.input, expectedInput, 'Match input'); |
There was a problem hiding this comment.
This should also take an expectedGroups argument, since match will either lack a groups property, or have one that's a null object when named capture group syntax is used.
There was a problem hiding this comment.
I've rebased your branch and am going to merge it; so we can do that in a followup.
Tests were updated and assume tc39/proposal-string-matchall#33 will be merged.
In an attempt to make it easier to see the coverage these tests provides, here's a version of the specification annotated with links to the related test from this PR: https://gist.github.com/peterwmwong/2a9d80d3533c0ab165bc8c675ac99e45 (Example below)
I haven't had the honor of contributing to Test262, so I'm not sure if I've made some bad cross cutting decisions...
const/letovervarfeatures, I'm addingString.prototype.matchAllandSymbol.matchAll@ljharb I totally defer to you as you're the expert, let me know whatever I can do to make these tests better!
Thanks!
PS - If you'd like to try out my in-progress V8 implementation, checkout my branch or download the pre-built MacOS X binary here (zip): https://gist.github.com/peterwmwong/e38b50689d7717870b2cff7b68574b87