diff --git a/test/built-ins/Array/prototype/flatMap/array-like-objects.js b/test/built-ins/Array/prototype/flatMap/array-like-objects.js new file mode 100644 index 0000000000000000000000000000000000000000..dcb9f5c9ca837987f8f4a32f507862317d756237 --- /dev/null +++ b/test/built-ins/Array/prototype/flatMap/array-like-objects.js @@ -0,0 +1,33 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatMap +description: > + array-like objects can be flattened +includes: [compareArray.js] +---*/ + +function takesTwoParams(a, b) { + return Array.prototype.flatMap.call(arguments, function(ele) { return ele * 2}); +} + +var actual = takesTwoParams(1,[2]); +var expected = [2, 4]; + +assert(compareArray(actual, expected), 'arguments array like object'); + +var a = { + "length": 1, + "0": 1 +}; + +actual = Array.prototype.flatMap.call(a, function(ele) { return ele * 2}); +assert.sameValue(JSON.stringify(actual), JSON.stringify(['2']), 'array like objects'); + +var a = { + "length": undefined, + "0": 1 +}; + +actual = Array.prototype.flatMap.call(a, function(ele) { return ele * 2}); +assert.sameValue(JSON.stringify(actual), JSON.stringify([]), 'array like objects'); diff --git a/test/built-ins/Array/prototype/flatMap/bound-function-argument.js b/test/built-ins/Array/prototype/flatMap/bound-function-argument.js new file mode 100644 index 0000000000000000000000000000000000000000..b85b9aaa3d3ed076a91709f6a620284b7c78d7c2 --- /dev/null +++ b/test/built-ins/Array/prototype/flatMap/bound-function-argument.js @@ -0,0 +1,13 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatMap +description: > + Behavior when array is depth more than 1 +includes: [compareArray.js] +---*/ + +var a = [void 0,[void 0]]; +var flattenMap = [].flatMap.bind(a, function() {}); + +assert.compareArray(a.flatMap(flattenMap), [undefined, undefined, undefined, undefined]); diff --git a/test/built-ins/Array/prototype/flatMap/depth-always-one.js b/test/built-ins/Array/prototype/flatMap/depth-always-one.js new file mode 100644 index 0000000000000000000000000000000000000000..624392c2dc2c6d5aedf42ebab6a9cbf23ab823f0 --- /dev/null +++ b/test/built-ins/Array/prototype/flatMap/depth-always-one.js @@ -0,0 +1,24 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatMap +description: > + Behavior when array is depth more than 1 +includes: [compareArray.js] +---*/ + +assert(compareArray([1, [2]].flatMap(function(ele) { + return ele * 2; +}), [2, 4]), 'array depth is 1'); + +assert(compareArray([1, [2], [[3]]].flatMap(function(ele) { + return ele * 2; +}), [2, 4, 6]), 'array depth is more than 1'); + +var actual = [1, [2], [3, [3]]].flatMap(function(ele) { + return ele * 2; +}); + +assert.sameValue(actual[0], 2); +assert.sameValue(actual[1], 4); +assert(isNaN(actual[2])); diff --git a/test/built-ins/Array/prototype/flatMap/length.js b/test/built-ins/Array/prototype/flatMap/length.js new file mode 100644 index 0000000000000000000000000000000000000000..e93fc14680c6540181117c1931bc1324d449153a --- /dev/null +++ b/test/built-ins/Array/prototype/flatMap/length.js @@ -0,0 +1,18 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: sec-array.prototype.flatMap +description: Array.prototype.flatMap.length value and descriptor. +info: > + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Array.prototype.flatMap.length, 1, + 'The value of `Array.prototype.flatmap.length` is `1`' +); + +verifyNotEnumerable(Array.prototype.flatMap, 'length'); +verifyNotWritable(Array.prototype.flatMap, 'length'); +verifyConfigurable(Array.prototype.flatMap, 'length'); diff --git a/test/built-ins/Array/prototype/flatMap/name.js b/test/built-ins/Array/prototype/flatMap/name.js new file mode 100644 index 0000000000000000000000000000000000000000..7d0bff174512b2e686340680b83dc99a64be8bcb --- /dev/null +++ b/test/built-ins/Array/prototype/flatMap/name.js @@ -0,0 +1,18 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: sec-array.prototype.flatmap +description: Array.prototype.flatmap name value and descriptor. +info: > + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Array.prototype.flatMap.name, 'flatMap', + 'The value of `Array.prototype.flatMap.name` is `"flatMap"`' +); + +verifyNotEnumerable(Array.prototype.flatMap, 'name'); +verifyNotWritable(Array.prototype.flatMap, 'name'); +verifyConfigurable(Array.prototype.flatMap, 'name'); diff --git a/test/built-ins/Array/prototype/flatMap/non-callable-argument-throws.js b/test/built-ins/Array/prototype/flatMap/non-callable-argument-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..9c46e7d5bd949f1a7ca091a729fe322004df5335 --- /dev/null +++ b/test/built-ins/Array/prototype/flatMap/non-callable-argument-throws.js @@ -0,0 +1,11 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatMap +description: > + non callable argument should throw TypeError Exception +---*/ + +assert.throws(TypeError, function () { + [].flatMap({}); +}, 'non callable argument'); diff --git a/test/built-ins/Array/prototype/flatMap/non-object-ctor-throws.js b/test/built-ins/Array/prototype/flatMap/non-object-ctor-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..962bd16fb4cf16b204cab0b6496f2250344a8972 --- /dev/null +++ b/test/built-ins/Array/prototype/flatMap/non-object-ctor-throws.js @@ -0,0 +1,34 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatMap +description: > + Behavior when `constructor` property is neither an Object nor undefined + - if IsConstructor(C) is false, throw a TypeError exception. +---*/ + +var a = []; + +a.constructor = null; +assert.throws(TypeError, function() { + a.flatMap(); +}, 'null value'); + +a = []; +a.constructor = 1; +assert.throws(TypeError, function() { + a.flatMap(); +}, 'number value'); + +a = []; +a.constructor = 'string'; +assert.throws(TypeError, function() { + a.flatMap(); +}, 'string value'); + +a = []; +a.constructor = true; +assert.throws(TypeError, function() { + a.flatMap(); +}, 'boolean value'); + diff --git a/test/built-ins/Array/prototype/flatMap/null-undefined-input-throws.js b/test/built-ins/Array/prototype/flatMap/null-undefined-input-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..841d47734eb670171aacec455061d0e18656e175 --- /dev/null +++ b/test/built-ins/Array/prototype/flatMap/null-undefined-input-throws.js @@ -0,0 +1,20 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatMap +description: > + null or undefined should throw TypeError Exception +---*/ + +assert.throws(TypeError, function() { + [].flatMap.call(null); +}, 'null value'); + +assert.throws(TypeError, function() { + [].flatMap.call(); +}, 'missing'); + +assert.throws(TypeError, function() { + [].flatMap.call(void 0); +}, 'undefined'); + diff --git a/test/built-ins/Array/prototype/flatMap/thisArg-argument.js b/test/built-ins/Array/prototype/flatMap/thisArg-argument.js new file mode 100644 index 0000000000000000000000000000000000000000..097ec0c872ff08806a1066ebf0a87887c58ce7ad --- /dev/null +++ b/test/built-ins/Array/prototype/flatMap/thisArg-argument.js @@ -0,0 +1,20 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatMap +description: > + Behavior when thisArg is provided + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) +includes: [compareArray.js] +---*/ + +"use strict"; + +var a; + +assert(compareArray([1].flatMap(function() { return this}, "TestString"), ["TestString"])); +assert(compareArray([1].flatMap(function() { return this}, 1), [1])); +assert(compareArray([1].flatMap(function() { return this}, null), [null])); +assert(compareArray([1].flatMap(function() { return this}, true), [true])); +assert(compareArray([1].flatMap(function() { return this}, a = {}), [a])); +assert(compareArray([1].flatMap(function() { return this}, void 0), [undefined])); diff --git a/test/built-ins/Array/prototype/flatten/array-like-objects.js b/test/built-ins/Array/prototype/flatten/array-like-objects.js new file mode 100644 index 0000000000000000000000000000000000000000..d4a210444b21a9273c837c4166f60b61fa8cf0a5 --- /dev/null +++ b/test/built-ins/Array/prototype/flatten/array-like-objects.js @@ -0,0 +1,31 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatten +description: > + array-like objects can be flattened +includes: [compareArray.js] +---*/ + +function takesTwoParams(a, b) { + return Array.prototype.flatten.call(arguments); +} + +var actual = takesTwoParams(1,[2]); +var expected = [1, 2]; + +assert(compareArray(actual, expected), 'arguments array like object'); + +var a = { + "length": 1, + "0": 'a' +}; + +actual = Array.prototype.flatten.call(a); +assert.sameValue(JSON.stringify(actual), JSON.stringify(['a']), 'array like objects'); + +a = { + "length": undefined, + "0": 'a' +}; +assert.sameValue(JSON.stringify(actual), JSON.stringify([]), 'array like objects undefined length'); diff --git a/test/built-ins/Array/prototype/flatten/bound-function-call.js b/test/built-ins/Array/prototype/flatten/bound-function-call.js new file mode 100644 index 0000000000000000000000000000000000000000..e456ba0318a146cf293a1189ef0b7c46528407d0 --- /dev/null +++ b/test/built-ins/Array/prototype/flatten/bound-function-call.js @@ -0,0 +1,13 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatten +description: > + using bound functions +includes: [compareArray.js] +---*/ + +var a = [1,[1]]; +var flattenIt = [].flatten.bind(a); + +assert(compareArray(flattenIt(), [1, 1]), 'bound functions'); diff --git a/test/built-ins/Array/prototype/flatten/empty-array-elements.js b/test/built-ins/Array/prototype/flatten/empty-array-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..ebcf785869a5a07f7afe3d73f63efafbe60337d6 --- /dev/null +++ b/test/built-ins/Array/prototype/flatten/empty-array-elements.js @@ -0,0 +1,15 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatten +description: > + arrays with empty arrays elements +includes: [compareArray.js] +---*/ + +var a; +assert(compareArray([].flatten([[]]), [])); +assert(compareArray(Array.prototype.flatten.call([[], []]), [])); +assert(compareArray(Array.prototype.flatten.call([[], [1]]), [1])); +assert(compareArray(Array.prototype.flatten.call([[], [1, a = []]]), [1, a])); +assert.sameValue(JSON.stringify(Array.prototype.flatten.call([{}, []])), JSON.stringify([{}])); diff --git a/test/built-ins/Array/prototype/flatten/empty-object-elements.js b/test/built-ins/Array/prototype/flatten/empty-object-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..6bc6086c814744bc332f19a111bdfed467d9c3fe --- /dev/null +++ b/test/built-ins/Array/prototype/flatten/empty-object-elements.js @@ -0,0 +1,12 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatten +description: > + arrays with empty object elements +---*/ + +assert.sameValue(JSON.stringify(Array.prototype.flatten.call([{}])), JSON.stringify([{}])); +assert.sameValue(JSON.stringify(Array.prototype.flatten.call([{}, [{}]])), JSON.stringify([{}, {}])); +assert.sameValue(JSON.stringify(Array.prototype.flatten.call([[{null: {}}], [{}]])), JSON.stringify([{null: {}}, {}])); +assert.sameValue(JSON.stringify(Array.prototype.flatten.call([[{null: null}], [{}]])), JSON.stringify([{null: null}, {}])); diff --git a/test/built-ins/Array/prototype/flatten/length.js b/test/built-ins/Array/prototype/flatten/length.js new file mode 100644 index 0000000000000000000000000000000000000000..1f32fecc818e16216d0a8a91da67dbf946ee7979 --- /dev/null +++ b/test/built-ins/Array/prototype/flatten/length.js @@ -0,0 +1,18 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: sec-array.prototype.flatten +description: Array.prototype.flatten.length value and descriptor. +info: > + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Array.prototype.flatten.length, 0, + 'The value of `Array.prototype.flatten.length` is `0`' +); + +verifyNotEnumerable(Array.prototype.flatten, 'length'); +verifyNotWritable(Array.prototype.flatten, 'length'); +verifyConfigurable(Array.prototype.flatten, 'length'); diff --git a/test/built-ins/Array/prototype/flatten/name.js b/test/built-ins/Array/prototype/flatten/name.js new file mode 100644 index 0000000000000000000000000000000000000000..3344833fee976e6f32d7072a1331d9bf158bd3e0 --- /dev/null +++ b/test/built-ins/Array/prototype/flatten/name.js @@ -0,0 +1,20 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatten +description: > + Array.prototype.flatten.name value and descriptor. +info: > + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Array.prototype.flatten.name, 'flatten', + 'The value of `Array.prototype.flatten.name` is `"flatten"`' +); + +verifyNotEnumerable(Array.prototype.flatten, 'name'); +verifyNotWritable(Array.prototype.flatten, 'name'); +verifyConfigurable(Array.prototype.flatten, 'name'); + diff --git a/test/built-ins/Array/prototype/flatten/non-numeric-depth-should-not-throw.js b/test/built-ins/Array/prototype/flatten/non-numeric-depth-should-not-throw.js new file mode 100644 index 0000000000000000000000000000000000000000..52f0892464553aca5a623860cd2363e43de4ccf8 --- /dev/null +++ b/test/built-ins/Array/prototype/flatten/non-numeric-depth-should-not-throw.js @@ -0,0 +1,42 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatten +description: > + if the argument is a string or object, the depthNum is 0 +includes: [compareArray.js] +---*/ + +var a = [1, [2]]; +var expected = a; + +// non integral string depthNum is converted to 0 +var depthNum = 'TestString'; +var actual = a.flatten(depthNum); +assert(compareArray(actual, expected), 'non integral string depthNum'); + +// object type depthNum is converted to 0 +depthNum = {}; +var actual = a.flatten(depthNum); +assert(compareArray(actual, expected), 'object type depthNum'); + +// negative infinity depthNum is converted to 0 +depthNum = Number.NEGATIVE_INFINITY; +var actual = a.flatten(depthNum); +assert(compareArray(actual, expected), 'negative infinity depthNum'); + +// positive zero depthNum is converted to 0 +depthNum = +0; +var actual = a.flatten(depthNum); +assert(compareArray(actual, expected), 'positive zero depthNum'); + +// negative zero depthNum is converted to 0 +depthNum = -0; +var actual = a.flatten(depthNum); +assert(compareArray(actual, expected), 'negative zero depthNum'); + +// integral string depthNum is converted to an integer +depthNum = '1'; +var actual = a.flatten(depthNum); +expected = [1, 2] +assert(compareArray(actual, expected), 'integral string depthNum'); diff --git a/test/built-ins/Array/prototype/flatten/non-object-ctor-throws.js b/test/built-ins/Array/prototype/flatten/non-object-ctor-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..853ee8cd78171b260a538a78b8f8e830de7b8ade --- /dev/null +++ b/test/built-ins/Array/prototype/flatten/non-object-ctor-throws.js @@ -0,0 +1,33 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatten +description: > + Behavior when `constructor` property is neither an Object nor undefined + - if IsConstructor(C) is false, throw a TypeError exception. +---*/ + +var a = []; + +a.constructor = null; +assert.throws(TypeError, function() { + a.flatten(); +}, 'null value'); + +a = []; +a.constructor = 1; +assert.throws(TypeError, function() { + a.flatten(); +}, 'number value'); + +a = []; +a.constructor = 'string'; +assert.throws(TypeError, function() { + a.flatten(); +}, 'string value'); + +a = []; +a.constructor = true; +assert.throws(TypeError, function() { + a.flatten(); +}, 'boolean value'); diff --git a/test/built-ins/Array/prototype/flatten/null-undefined-elements.js b/test/built-ins/Array/prototype/flatten/null-undefined-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..247be9a8a6e41cb5d99322c5cb35adb0e69badfa --- /dev/null +++ b/test/built-ins/Array/prototype/flatten/null-undefined-elements.js @@ -0,0 +1,15 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatten +description: > + arrays with null, and undefined +includes: [compareArray.js] +---*/ +var a; + +assert(compareArray(Array.prototype.flatten.call([1, null, void 0]), [1, null, undefined])); +assert(compareArray(Array.prototype.flatten.call([1,[null, void 0]]), [1, null, undefined])); +assert(compareArray(Array.prototype.flatten.call([[null, void 0], [null, void 0]]), [null, undefined, null, undefined])); +assert(compareArray(Array.prototype.flatten.call([1,[null, a = [void 0]]], 1), [1, null, a])); +assert(compareArray(Array.prototype.flatten.call([1,[null, [void 0]]], 2), [1, null, undefined])); diff --git a/test/built-ins/Array/prototype/flatten/null-undefined-input-throws.js b/test/built-ins/Array/prototype/flatten/null-undefined-input-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..443840ff0fdffebc405b4c509cb40720775471a4 --- /dev/null +++ b/test/built-ins/Array/prototype/flatten/null-undefined-input-throws.js @@ -0,0 +1,20 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatten +description: > + null or undefined should throw TypeError Exception +---*/ + +assert.throws(TypeError, function() { + [].flatten.call(null); +}, 'null value'); + +assert.throws(TypeError, function() { + [].flatten.call(); +}, 'missing'); + +assert.throws(TypeError, function() { + [].flatten.call(void 0); +}, 'undefined'); + diff --git a/test/built-ins/Array/prototype/flatten/positive-infinity.js b/test/built-ins/Array/prototype/flatten/positive-infinity.js new file mode 100644 index 0000000000000000000000000000000000000000..ea2f882e79581cc98bf0b99c8bef7e5f93c3ec77 --- /dev/null +++ b/test/built-ins/Array/prototype/flatten/positive-infinity.js @@ -0,0 +1,11 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatten +description: > + if the argument is a positive infinity, the depthNum is max depth of the array +includes: [compareArray.js] +---*/ + +var a = [1, [2, [3, [4]]]] +assert(compareArray(a.flatten(Number.POSITIVE_INFINITY), [1, 2, 3, 4]), 'positive infinity depthNum'); diff --git a/test/built-ins/Array/prototype/flatten/prop-desc.js b/test/built-ins/Array/prototype/flatten/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..3dc6fe3291395e9aa875ac9da24cee834e1eb2a0 --- /dev/null +++ b/test/built-ins/Array/prototype/flatten/prop-desc.js @@ -0,0 +1,20 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatten +es6id: 22.1.3 +description: Property type and descriptor. +info: > + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof Array.prototype.flatten, + 'function', + '`typeof Array.prototype.flatten` is `function`' +); + +verifyNotEnumerable(Array.prototype, 'flatten'); +verifyWritable(Array.prototype, 'flatten'); +verifyConfigurable(Array.prototype, 'flatten'); diff --git a/test/built-ins/Array/prototype/flatten/symbol-object-create-null-depth-throws.js b/test/built-ins/Array/prototype/flatten/symbol-object-create-null-depth-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..b12046925dc7f2e319919c93afeb0a05ed53044a --- /dev/null +++ b/test/built-ins/Array/prototype/flatten/symbol-object-create-null-depth-throws.js @@ -0,0 +1,21 @@ +// Copyright (C) 2018 Shilpi Jain. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.flatten +description: > + if the argument is a Symbol or Object null, it throws exception +---*/ + +var a = []; +var depthNum = Symbol(); + +assert.throws(TypeError, function() { + a.flatten(depthNum); +}, 'symbol value'); + +depthNum = Object.create(null); + +assert.throws(TypeError, function() { + a.flatten(depthNum); +}, 'object create null'); +