mirror of
https://github.com/tc39/test262.git
synced 2025-07-05 05:04:42 +02:00
Update tests for String.prototype.matchAll (#1990)
- Changes associated with spec changes (tc39/proposal-string-matchall#41) - Update spec comments - Added test verifying error thrown when `regexp[Symbol.matchAll]` is not callable - Added test verifying `ToString` is called on `receiver`
This commit is contained in:
parent
b2597d060d
commit
c36bdcfeb3
@ -8,14 +8,9 @@ info: |
|
|||||||
1. Let O be ? RequireObjectCoercible(this value).
|
1. Let O be ? RequireObjectCoercible(this value).
|
||||||
2. If regexp is neither undefined nor null, then
|
2. If regexp is neither undefined nor null, then
|
||||||
[...]
|
[...]
|
||||||
3. Return ? MatchAllIterator(regexp, O).
|
3. Let S be ? ToString(O).
|
||||||
|
4. Let rx be ? RegExpCreate(R, "g").
|
||||||
MatchAllIterator( regexp, O )
|
5. Return ? Invoke(rx, @@matchAll, « S »).
|
||||||
[...]
|
|
||||||
2. If ? IsRegExp(regexp) is true, then
|
|
||||||
[...]
|
|
||||||
3. Else,
|
|
||||||
a. Let R be RegExpCreate(regexp, "g").
|
|
||||||
features: [String.prototype.matchAll]
|
features: [String.prototype.matchAll]
|
||||||
includes: [compareArray.js, compareIterator.js, regExpUtils.js]
|
includes: [compareArray.js, compareIterator.js, regExpUtils.js]
|
||||||
---*/
|
---*/
|
||||||
|
30
test/built-ins/String/prototype/matchAll/regexp-is-undefined-or-null-invokes-matchAll.js
vendored
Normal file
30
test/built-ins/String/prototype/matchAll/regexp-is-undefined-or-null-invokes-matchAll.js
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2018 Peter Wong. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: pending
|
||||||
|
description: Behavior when regexp is null or undefined
|
||||||
|
info: |
|
||||||
|
String.prototype.matchAll ( regexp )
|
||||||
|
1. Let O be ? RequireObjectCoercible(this value).
|
||||||
|
2. If regexp is neither undefined nor null, then
|
||||||
|
[...]
|
||||||
|
3. Let S be ? ToString(O).
|
||||||
|
4. Let rx be ? RegExpCreate(R, "g").
|
||||||
|
5. Return ? Invoke(rx, @@matchAll, « S »).
|
||||||
|
features: [String.prototype.matchAll]
|
||||||
|
includes: [compareArray.js, compareIterator.js, regExpUtils.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var callCount = 0;
|
||||||
|
var obj = {};
|
||||||
|
RegExp.prototype[Symbol.matchAll] = function() {
|
||||||
|
callCount++;
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.sameValue('a'.matchAll(null), obj);
|
||||||
|
assert.sameValue(callCount, 1);
|
||||||
|
|
||||||
|
assert.sameValue(''.matchAll(undefined), obj);
|
||||||
|
assert.sameValue(callCount, 2);
|
||||||
|
|
38
test/built-ins/String/prototype/matchAll/regexp-matchAll-is-undefined-or-null.js
vendored
Normal file
38
test/built-ins/String/prototype/matchAll/regexp-matchAll-is-undefined-or-null.js
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// Copyright (C) 2018 Peter Wong. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: pending
|
||||||
|
description: Behavior when regexp[@@matchAll] is undefined or null
|
||||||
|
info: |
|
||||||
|
String.prototype.matchAll ( regexp )
|
||||||
|
1. Let O be ? RequireObjectCoercible(this value).
|
||||||
|
2. If regexp is neither undefined nor null, then
|
||||||
|
a. Let matcher be ? GetMethod(regexp, @@matchAll).
|
||||||
|
b. If matcher is not undefined, then
|
||||||
|
[...]
|
||||||
|
3. Let S be ? ToString(O).
|
||||||
|
4. Let rx be ? RegExpCreate(R, "g").
|
||||||
|
5. Return ? Invoke(rx, @@matchAll, « S »).
|
||||||
|
features: [Symbol.matchAll, String.prototype.matchAll]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var regexp = /./;
|
||||||
|
var callCount = 0;
|
||||||
|
var arg;
|
||||||
|
var obj = {};
|
||||||
|
var str = 'abc';
|
||||||
|
RegExp.prototype[Symbol.matchAll] = function(string) {
|
||||||
|
arg = string;
|
||||||
|
callCount++;
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
regexp[Symbol.matchAll] = undefined;
|
||||||
|
assert.sameValue(str.matchAll(regexp), obj);
|
||||||
|
assert.sameValue(arg, str);
|
||||||
|
assert.sameValue(callCount, 1);
|
||||||
|
|
||||||
|
regexp[Symbol.matchAll] = null;
|
||||||
|
assert.sameValue(str.matchAll(regexp), obj);
|
||||||
|
assert.sameValue(arg, str);
|
||||||
|
assert.sameValue(callCount, 2);
|
34
test/built-ins/String/prototype/matchAll/regexp-matchAll-not-callable.js
vendored
Normal file
34
test/built-ins/String/prototype/matchAll/regexp-matchAll-not-callable.js
vendored
Normal file
@ -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.
|
||||||
|
/*---
|
||||||
|
esid: pending
|
||||||
|
description: Behavior when regexp[@@matchAll] is not callable
|
||||||
|
info: |
|
||||||
|
String.prototype.matchAll ( regexp )
|
||||||
|
[...]
|
||||||
|
2. If regexp is neither undefined nor null, then
|
||||||
|
a. Let matcher be ? GetMethod(regexp, @@matchAll).
|
||||||
|
features: [Symbol.matchAll, String.prototype.matchAll]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var regexp = /./;
|
||||||
|
|
||||||
|
regexp[Symbol.matchAll] = true;
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
''.matchAll(regexp);
|
||||||
|
});
|
||||||
|
|
||||||
|
regexp[Symbol.matchAll] = 5;
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
''.matchAll(regexp);
|
||||||
|
});
|
||||||
|
|
||||||
|
regexp[Symbol.matchAll] = '';
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
''.matchAll(regexp);
|
||||||
|
});
|
||||||
|
|
||||||
|
regexp[Symbol.matchAll] = Symbol();
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
''.matchAll(regexp);
|
||||||
|
});
|
@ -11,17 +11,9 @@ info: |
|
|||||||
b. If matcher is not undefined, then
|
b. If matcher is not undefined, then
|
||||||
[...]
|
[...]
|
||||||
[...]
|
[...]
|
||||||
4. Let matcher be ? RegExpCreate(R, "g").
|
4. Let rx be ? RegExpCreate(R, "g").
|
||||||
[...]
|
5. Return ? Invoke(rx, @@matchAll, « S »).
|
||||||
|
|
||||||
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]
|
features: [Symbol.matchAll, String.prototype.matchAll]
|
||||||
includes: [compareArray.js, compareIterator.js, regExpUtils.js]
|
includes: [compareArray.js, compareIterator.js, regExpUtils.js]
|
||||||
---*/
|
---*/
|
||||||
@ -29,7 +21,6 @@ includes: [compareArray.js, compareIterator.js, regExpUtils.js]
|
|||||||
delete RegExp.prototype[Symbol.matchAll];
|
delete RegExp.prototype[Symbol.matchAll];
|
||||||
var str = '/a/g*/b/g';
|
var str = '/a/g*/b/g';
|
||||||
|
|
||||||
assert.compareIterator(str.matchAll(/\w/g), [
|
assert.throws(TypeError, function() {
|
||||||
matchValidator(['/a/g'], 0, str),
|
str.matchAll(/\w/g);
|
||||||
matchValidator(['/b/g'], 5, str)
|
});
|
||||||
]);
|
|
||||||
|
41
test/built-ins/String/prototype/matchAll/toString-this-val.js
vendored
Normal file
41
test/built-ins/String/prototype/matchAll/toString-this-val.js
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (C) 2018 Peter Wong. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: pending
|
||||||
|
description: |
|
||||||
|
Verify ToString is called when regexp[@@matchAll] is undefined or null
|
||||||
|
info: |
|
||||||
|
String.prototype.matchAll ( regexp )
|
||||||
|
1. Let O be ? RequireObjectCoercible(this value).
|
||||||
|
2. If regexp is neither undefined nor null, then
|
||||||
|
a. Let matcher be ? GetMethod(regexp, @@matchAll).
|
||||||
|
b. If matcher is not undefined, then
|
||||||
|
[...]
|
||||||
|
3. Let S be ? ToString(O).
|
||||||
|
4. Let rx be ? RegExpCreate(R, "g").
|
||||||
|
5. Return ? Invoke(rx, @@matchAll, « S »).
|
||||||
|
features: [Symbol.matchAll, String.prototype.matchAll]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var regexp = /./;
|
||||||
|
var callCount = 0;
|
||||||
|
var arg;
|
||||||
|
var obj = {};
|
||||||
|
var toStringResult = 'abc';
|
||||||
|
var receiver = {
|
||||||
|
[Symbol.toPrimitive]: function() {
|
||||||
|
callCount++;
|
||||||
|
return toStringResult;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
RegExp.prototype[Symbol.matchAll] = function(string) {
|
||||||
|
arg = string;
|
||||||
|
};
|
||||||
|
|
||||||
|
String.prototype.matchAll.call(receiver, null);
|
||||||
|
assert.sameValue(callCount, 1);
|
||||||
|
assert.sameValue(arg, toStringResult);
|
||||||
|
|
||||||
|
String.prototype.matchAll.call(receiver, undefined);
|
||||||
|
assert.sameValue(callCount, 2);
|
||||||
|
assert.sameValue(arg, toStringResult);
|
Loading…
x
Reference in New Issue
Block a user