Update matchAll tests to reflect latest spec proposal

This commit is contained in:
André Bargull 2018-09-24 08:49:36 -04:00 committed by Rick Waldron
parent 46fcbf81d1
commit 3febd4c536
5 changed files with 45 additions and 42 deletions

View File

@ -5,16 +5,15 @@ esid: pending
description: IsRegExp should only be called once
info: |
RegExp.prototype [ @@matchAll ] ( string )
1. Let R be the this value.
[...]
3. Return ? MatchAllIterator(R, string).
4. Let C be ? SpeciesConstructor(R, %RegExp%).
5. Let flags be ? ToString(? Get(R, "flags")).
6. Let matcher be ? Construct(C, « R, flags »).
MatchAllIterator ( R, O )
21.2.3.1 RegExp ( pattern, flags )
1. Let patternIsRegExp be ? IsRegExp(pattern).
[...]
2. If ? IsRegExp(R) is true, then
[...]
3. Else,
a. Let flags be "g".
b. Let matcher be ? RegExpCreate(R, flags).
features: [Symbol.match, Symbol.matchAll]
---*/
@ -31,7 +30,8 @@ var o = {
get [Symbol.match]() {
++count;
return false;
}
},
flags: "",
};
RegExp.prototype[Symbol.matchAll].call(o, '1');

View File

@ -6,14 +6,13 @@ description: Custom species constructor is called when creating internal RegExp
info: |
RegExp.prototype [ @@matchAll ] ( string )
[...]
3. Return ? MatchAllIterator(R, string).
MatchAllIterator ( R, O )
4. Let C be ? SpeciesConstructor(R, %RegExp%).
5. Let flags be ? ToString(? Get(R, "flags")).
6. Let matcher be ? Construct(C, « R, flags »).
[...]
9. If flags contains "g", let global be true.
10. Else, let global be false.
[...]
2. If ? IsRegExp(R) is true, then
a. Let C be ? SpeciesConstructor(R, RegExp).
b. Let flags be ? ToString(? Get(R, "flags"))
c. Let matcher be ? Construct(C, R, flags).
features: [Symbol.matchAll, Symbol.species]
includes: [compareArray.js, compareIterator.js, regExpUtils.js]
---*/
@ -38,5 +37,4 @@ assert.sameValue(callArgs[1], 'u');
assert.compareIterator(iter, [
matchValidator(['a'], 0, str),
matchValidator(['b'], 2, str)
]);

View File

@ -3,18 +3,17 @@
/*---
esid: pending
description: |
Re-throws errors thrown while accessing species constructed RegExp's
global property
Doesn't access the "global" property of the constructed RegExp
info: |
RegExp.prototype [ @@matchAll ] ( string )
[...]
3. Return ? MatchAllIterator(R, string).
MatchAllIterator ( R, O )
4. Let C be ? SpeciesConstructor(R, %RegExp%).
5. Let flags be ? ToString(? Get(R, "flags")).
6. Let matcher be ? Construct(C, « R, flags »).
[...]
9. If flags contains "g", let global be true.
10. Else, let global be false.
[...]
2. If ? IsRegExp(R) is true, then
[...]
d. Let global be ? ToBoolean(? Get(matcher, "global")).
features: [Symbol.matchAll, Symbol.species]
---*/
@ -29,6 +28,4 @@ regexp.constructor = {
}
};
assert.throws(Test262Error, function() {
regexp[Symbol.matchAll]('');
});
regexp[Symbol.matchAll]('');

View File

@ -3,18 +3,17 @@
/*---
esid: pending
description: |
Re-throws errors thrown while accessing species constructed RegExp's
unicode property
Doesn't access the "unicode" property of the constructed RegExp
info: |
RegExp.prototype [ @@matchAll ] ( string )
[...]
3. Return ? MatchAllIterator(R, string).
MatchAllIterator ( R, O )
4. Let C be ? SpeciesConstructor(R, %RegExp%).
5. Let flags be ? ToString(? Get(R, "flags")).
6. Let matcher be ? Construct(C, « R, flags »).
[...]
11. If flags contains "u", let fullUnicode be true.
12. Else, let fullUnicode be false.
[...]
2. If ? IsRegExp(R) is true, then
[...]
e. Let fullUnicode be ? ToBoolean(? Get(matcher, "unicode")).
features: [Symbol.matchAll, Symbol.species]
---*/
@ -29,6 +28,4 @@ regexp.constructor = {
}
};
assert.throws(Test262Error, function() {
regexp[Symbol.matchAll]('');
});
regexp[Symbol.matchAll]('');

View File

@ -10,15 +10,26 @@ info: |
a. Let matcher be ? GetMethod(regexp, @@matchAll).
b. If matcher is not undefined, then
[...]
3. Return ? MatchAllIterator(regexp, O).
[...]
4. Let matcher be ? RegExpCreate(R, "g").
[...]
21.2.3.2.3 Runtime Semantics: RegExpCreate ( P, F )
[...]
2. Return ? RegExpInitialize(obj, P, F).
21.2.3.2.2 Runtime Semantics: RegExpInitialize ( obj, pattern, flags )
1. If pattern is undefined, let P be the empty String.
2. Else, let P be ? ToString(pattern).
[...]
features: [Symbol.matchAll, String.prototype.matchAll]
includes: [compareArray.js, compareIterator.js, regExpUtils.js]
---*/
delete RegExp.prototype[Symbol.matchAll];
var str = 'a*b';
var str = '/a/g*/b/g';
assert.compareIterator(str.matchAll(/\w/g), [
matchValidator(['a'], 0, str),
matchValidator(['b'], 2, str)
matchValidator(['/a/g'], 0, str),
matchValidator(['/b/g'], 5, str)
]);