-
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is now: species-constructor-get-species-throws.js
@@ -1,36 +0,0 @@ | |||
// Copyright (C) 2018 Jordan Harband. All rights reserved. |
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 test is now: this-not-object-throws.js
@@ -1,22 +0,0 @@ | |||
// Copyright (C) 2018 Jordan Harband. All rights reserved. |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is now:
@@ -1,43 +0,0 @@ | |||
// Copyright (C) 2018 Jordan Harband. All rights reserved. |
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 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.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests generally don’t need to clean up after themselves; each test is run in its own environment.
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.
Great! Removed: 7decf6a
|
||
assert.sameValue(RegExpStringIteratorProto.next.length, 0); | ||
|
||
verifyNotEnumerable(RegExpStringIteratorProto.next, "length"); |
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.
We should try to use consistent quotes in this pr; probably single over double?
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.
Absolutely, fixed: 0c1492d
const str = 'a*b'; | ||
const iter = regexp[Symbol.matchAll](str); | ||
|
||
let { value, done } = iter.next(); |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
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.
Thank you!!
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.
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, 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.
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.
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
/let
overvar
features
, I'm addingString.prototype.matchAll
andSymbol.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