forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update tests for String.prototype.matchAll
- 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`
- Loading branch information
1 parent
b2597d0
commit 83b976e
Showing
6 changed files
with
151 additions
and
22 deletions.
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
30 changes: 30 additions & 0 deletions
30
test/built-ins/String/prototype/matchAll/regexp-is-undefined-or-null-invokes-matchAll.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,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 changes: 38 additions & 0 deletions
38
test/built-ins/String/prototype/matchAll/regexp-matchAll-is-undefined-or-null.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,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 changes: 34 additions & 0 deletions
34
test/built-ins/String/prototype/matchAll/regexp-matchAll-not-callable.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,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); | ||
}); |
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
41 changes: 41 additions & 0 deletions
41
test/built-ins/String/prototype/matchAll/toString-this-val.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,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); |