From e15be1853b7e04b656f2d43dca3b337db9d79fef Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 25 Jan 2018 23:45:12 -0800 Subject: [PATCH] String.prototype.matchAll: add tests for stage 3 `RegExp.prototype[Symbol.matchAll]`: Add basic tests. --- .../prototype/Symbol.matchAll/coerce-arg.js | 27 ++++++++++++++ .../get-species-constructor-err.js | 22 ++++++++++++ .../prototype/Symbol.matchAll/length.js | 25 +++++++++++++ .../RegExp/prototype/Symbol.matchAll/name.js | 23 ++++++++++++ .../prototype/Symbol.matchAll/prop-desc.js | 19 ++++++++++ .../Symbol.matchAll/this-val-non-obj.js | 36 +++++++++++++++++++ .../Symbol.matchAll/this-val-non-regexp.js | 22 ++++++++++++ 7 files changed, 174 insertions(+) create mode 100644 test/built-ins/RegExp/prototype/Symbol.matchAll/coerce-arg.js create mode 100644 test/built-ins/RegExp/prototype/Symbol.matchAll/get-species-constructor-err.js create mode 100644 test/built-ins/RegExp/prototype/Symbol.matchAll/length.js create mode 100644 test/built-ins/RegExp/prototype/Symbol.matchAll/name.js create mode 100644 test/built-ins/RegExp/prototype/Symbol.matchAll/prop-desc.js create mode 100644 test/built-ins/RegExp/prototype/Symbol.matchAll/this-val-non-obj.js create mode 100644 test/built-ins/RegExp/prototype/Symbol.matchAll/this-val-non-regexp.js diff --git a/test/built-ins/RegExp/prototype/Symbol.matchAll/coerce-arg.js b/test/built-ins/RegExp/prototype/Symbol.matchAll/coerce-arg.js new file mode 100644 index 0000000000..b2557aae99 --- /dev/null +++ b/test/built-ins/RegExp/prototype/Symbol.matchAll/coerce-arg.js @@ -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); +}); diff --git a/test/built-ins/RegExp/prototype/Symbol.matchAll/get-species-constructor-err.js b/test/built-ins/RegExp/prototype/Symbol.matchAll/get-species-constructor-err.js new file mode 100644 index 0000000000..64028836ee --- /dev/null +++ b/test/built-ins/RegExp/prototype/Symbol.matchAll/get-species-constructor-err.js @@ -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); +}); diff --git a/test/built-ins/RegExp/prototype/Symbol.matchAll/length.js b/test/built-ins/RegExp/prototype/Symbol.matchAll/length.js new file mode 100644 index 0000000000..241d3d40ce --- /dev/null +++ b/test/built-ins/RegExp/prototype/Symbol.matchAll/length.js @@ -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'); diff --git a/test/built-ins/RegExp/prototype/Symbol.matchAll/name.js b/test/built-ins/RegExp/prototype/Symbol.matchAll/name.js new file mode 100644 index 0000000000..a755118e00 --- /dev/null +++ b/test/built-ins/RegExp/prototype/Symbol.matchAll/name.js @@ -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'); diff --git a/test/built-ins/RegExp/prototype/Symbol.matchAll/prop-desc.js b/test/built-ins/RegExp/prototype/Symbol.matchAll/prop-desc.js new file mode 100644 index 0000000000..df4f7955db --- /dev/null +++ b/test/built-ins/RegExp/prototype/Symbol.matchAll/prop-desc.js @@ -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); diff --git a/test/built-ins/RegExp/prototype/Symbol.matchAll/this-val-non-obj.js b/test/built-ins/RegExp/prototype/Symbol.matchAll/this-val-non-obj.js new file mode 100644 index 0000000000..b4469f2ac7 --- /dev/null +++ b/test/built-ins/RegExp/prototype/Symbol.matchAll/this-val-non-obj.js @@ -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); +}); diff --git a/test/built-ins/RegExp/prototype/Symbol.matchAll/this-val-non-regexp.js b/test/built-ins/RegExp/prototype/Symbol.matchAll/this-val-non-regexp.js new file mode 100644 index 0000000000..76a57831cb --- /dev/null +++ b/test/built-ins/RegExp/prototype/Symbol.matchAll/this-val-non-regexp.js @@ -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); +});