mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 14:04:51 +02:00
String.prototype.matchAll: add tests for stage 3
`RegExp.prototype[Symbol.matchAll]`: Add basic tests.
This commit is contained in:
parent
5b3914a37b
commit
e15be1853b
27
test/built-ins/RegExp/prototype/Symbol.matchAll/coerce-arg.js
vendored
Normal file
27
test/built-ins/RegExp/prototype/Symbol.matchAll/coerce-arg.js
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright (C) 2018 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: String coercion of string parameter
|
||||||
|
info: |
|
||||||
|
RegExp.prototype [ @@matchAll ] ( string )
|
||||||
|
|
||||||
|
[...]
|
||||||
|
2. Let S be ? ToString(O).
|
||||||
|
[...]
|
||||||
|
features: [Symbol.match, Symbol.matchAll]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
valueOf: function() {
|
||||||
|
$ERROR('This method should not be invoked.');
|
||||||
|
},
|
||||||
|
toString: function() {
|
||||||
|
throw new Test262Error('toString invoked');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
obj[Symbol.match] = true;
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function () {
|
||||||
|
/toString value/[Symbol.matchAll](obj);
|
||||||
|
});
|
22
test/built-ins/RegExp/prototype/Symbol.matchAll/get-species-constructor-err.js
vendored
Normal file
22
test/built-ins/RegExp/prototype/Symbol.matchAll/get-species-constructor-err.js
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
Behavior when error is thrown during retrieval of `Symbol.species` property
|
||||||
|
info: |
|
||||||
|
3. Let C be ? SpeciesConstructor(R, %RegExp%).
|
||||||
|
features: [Symbol.match, Symbol.matchAll, Symbol.species]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = {};
|
||||||
|
Object.defineProperty(obj, Symbol.species, {
|
||||||
|
get: function () {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
obj[Symbol.match] = true;
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
RegExp.prototype[Symbol.matchAll].call(obj);
|
||||||
|
});
|
25
test/built-ins/RegExp/prototype/Symbol.matchAll/length.js
vendored
Normal file
25
test/built-ins/RegExp/prototype/Symbol.matchAll/length.js
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2018 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: RegExp.prototype[Symbol.matchAll] `length` property
|
||||||
|
info: |
|
||||||
|
ES6 Section 17:
|
||||||
|
Every built-in Function object, including constructors, has a length
|
||||||
|
property whose value is an integer. Unless otherwise specified, this value
|
||||||
|
is equal to the largest number of named arguments shown in the subclause
|
||||||
|
headings for the function description, including optional parameters.
|
||||||
|
|
||||||
|
[...]
|
||||||
|
|
||||||
|
Unless otherwise specified, the length property of a built-in Function
|
||||||
|
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
|
||||||
|
[[Configurable]]: true }.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [Symbol.matchAll]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(RegExp.prototype[Symbol.matchAll].length, 1);
|
||||||
|
|
||||||
|
verifyNotEnumerable(RegExp.prototype[Symbol.matchAll], 'length');
|
||||||
|
verifyNotWritable(RegExp.prototype[Symbol.matchAll], 'length');
|
||||||
|
verifyConfigurable(RegExp.prototype[Symbol.matchAll], 'length');
|
23
test/built-ins/RegExp/prototype/Symbol.matchAll/name.js
vendored
Normal file
23
test/built-ins/RegExp/prototype/Symbol.matchAll/name.js
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (C) 2018 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: RegExp.prototype[Symbol.matchAll] `name` property
|
||||||
|
info: |
|
||||||
|
The value of the name property of this function is "[Symbol.matchAll]".
|
||||||
|
|
||||||
|
ES6 Section 17:
|
||||||
|
|
||||||
|
[...]
|
||||||
|
|
||||||
|
Unless otherwise specified, the name property of a built-in Function
|
||||||
|
object, if it exists, has the attributes { [[Writable]]: false,
|
||||||
|
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [Symbol.matchAll]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(RegExp.prototype[Symbol.matchAll].name, '[Symbol.matchAll]');
|
||||||
|
|
||||||
|
verifyNotEnumerable(RegExp.prototype[Symbol.matchAll], 'name');
|
||||||
|
verifyNotWritable(RegExp.prototype[Symbol.matchAll], 'name');
|
||||||
|
verifyConfigurable(RegExp.prototype[Symbol.matchAll], 'name');
|
19
test/built-ins/RegExp/prototype/Symbol.matchAll/prop-desc.js
vendored
Normal file
19
test/built-ins/RegExp/prototype/Symbol.matchAll/prop-desc.js
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2018 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: RegExp.prototype[Symbol.matchAll] property descriptor
|
||||||
|
info: |
|
||||||
|
ES6 Section 17
|
||||||
|
|
||||||
|
Every other data property described in clauses 18 through 26 and in Annex
|
||||||
|
B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||||
|
[[Configurable]]: true } unless otherwise specified.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [Symbol.matchAll]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof RegExp.prototype[Symbol.matchAll], 'function');
|
||||||
|
verifyNotEnumerable(RegExp.prototype, Symbol.matchAll);
|
||||||
|
verifyWritable(RegExp.prototype, Symbol.matchAll);
|
||||||
|
verifyConfigurable(RegExp.prototype, Symbol.matchAll);
|
36
test/built-ins/RegExp/prototype/Symbol.matchAll/this-val-non-obj.js
vendored
Normal file
36
test/built-ins/RegExp/prototype/Symbol.matchAll/this-val-non-obj.js
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Copyright (C) 2018 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: The `this` value must be an object
|
||||||
|
info: |
|
||||||
|
1. Let R be the this value.
|
||||||
|
2. Return ? MatchAllIterator(R, string).
|
||||||
|
[...]
|
||||||
|
1. If ? IsRegExp(R) is not true, throw a TypeError exception.
|
||||||
|
features: [Symbol.matchAll]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
RegExp.prototype[Symbol.matchAll].call(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
RegExp.prototype[Symbol.matchAll].call(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
RegExp.prototype[Symbol.matchAll].call(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
RegExp.prototype[Symbol.matchAll].call('string');
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
RegExp.prototype[Symbol.matchAll].call(Symbol.matchAll);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
RegExp.prototype[Symbol.matchAll].call(86);
|
||||||
|
});
|
22
test/built-ins/RegExp/prototype/Symbol.matchAll/this-val-non-regexp.js
vendored
Normal file
22
test/built-ins/RegExp/prototype/Symbol.matchAll/this-val-non-regexp.js
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright (C) 2018 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: The `this` value must be a regular expression (has Symbol.match)
|
||||||
|
info: |
|
||||||
|
1. Let R be the this value.
|
||||||
|
2. Return ? MatchAllIterator(R, string).
|
||||||
|
[...]
|
||||||
|
1. If ? IsRegExp(R) is not true, throw a TypeError exception.
|
||||||
|
features: [Symbol.match, Symbol.matchAll]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var regexObj = {};
|
||||||
|
regexObj[Symbol.match] = true;
|
||||||
|
var obj = {};
|
||||||
|
|
||||||
|
RegExp.prototype[Symbol.matchAll].call(regexObj);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
RegExp.prototype[Symbol.matchAll].call(obj);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user