summaryrefslogtreecommitdiff
path: root/test/built-ins/TypedArray
diff options
context:
space:
mode:
authorLeonardo Balter <leonardo.balter@gmail.com>2016-05-17 16:16:53 -0400
committerMike Pennisi <mike@mikepennisi.com>2016-05-25 10:31:55 -0400
commit56b988883e3e1819cdc98b21c125be4c80f2bc24 (patch)
treea5ac245f992cf225ef554f101521f9ed7bf98052 /test/built-ins/TypedArray
parentd3effa125f8661aa4f36915e17ef979b66a61b7f (diff)
downloadqtdeclarative-testsuites-56b988883e3e1819cdc98b21c125be4c80f2bc24.tar.gz
Add tests for %TypedArray%.prototype.includes
Diffstat (limited to 'test/built-ins/TypedArray')
-rw-r--r--test/built-ins/TypedArray/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js35
-rw-r--r--test/built-ins/TypedArray/prototype/includes/fromIndex-infinity.js43
-rw-r--r--test/built-ins/TypedArray/prototype/includes/fromIndex-minus-zero.js33
-rw-r--r--test/built-ins/TypedArray/prototype/includes/get-length-uses-internal-arraylength.js32
-rw-r--r--test/built-ins/TypedArray/prototype/includes/length-zero-returns-false.js38
-rw-r--r--test/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js33
-rw-r--r--test/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex.js36
-rw-r--r--test/built-ins/TypedArray/prototype/includes/samevaluezero.js43
-rw-r--r--test/built-ins/TypedArray/prototype/includes/search-found-returns-true.js43
-rw-r--r--test/built-ins/TypedArray/prototype/includes/search-not-found-returns-false.js41
-rw-r--r--test/built-ins/TypedArray/prototype/includes/tointeger-fromindex.js64
11 files changed, 441 insertions, 0 deletions
diff --git a/test/built-ins/TypedArray/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js b/test/built-ins/TypedArray/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js
new file mode 100644
index 000000000..45abb4828
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js
@@ -0,0 +1,35 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%typedarray%.prototype.includes
+description: Return false if fromIndex >= ArrayLength
+info: >
+ 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.includes is a distinct function that implements the
+ same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that
+ the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length".
+
+ 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
+
+ ...
+ 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
+ produces the value 0.)
+ 5. If n ≥ 0, then
+ a. Let k be n.
+ ...
+ 7. Repeat, while k < len
+ ...
+ 8. Return false.
+includes: [testTypedArray.js]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample;
+
+ sample = new TA(42);
+ assert.sameValue(sample.includes(0, 42), false);
+ assert.sameValue(sample.includes(0, 43), false);
+});
diff --git a/test/built-ins/TypedArray/prototype/includes/fromIndex-infinity.js b/test/built-ins/TypedArray/prototype/includes/fromIndex-infinity.js
new file mode 100644
index 000000000..7dca85ac0
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/includes/fromIndex-infinity.js
@@ -0,0 +1,43 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%typedarray%.prototype.includes
+description: handle Infinity values for fromIndex
+info: >
+ 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.includes is a distinct function that implements the
+ same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that
+ the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length".
+
+ 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
+
+ ...
+ 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
+ produces the value 0.)
+ 5. If n ≥ 0, then
+ a. Let k be n.
+ 6. Else n < 0,
+ a. Let k be len + n.
+ b. If k < 0, let k be 0.
+ 7. Repeat, while k < len
+ ...
+ 8. Return false.
+includes: [testTypedArray.js]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([42, 43, 43, 41]);
+
+ assert.sameValue(
+ sample.includes(43, Infinity),
+ false,
+ "includes(43, Infinity)"
+ );
+ assert.sameValue(
+ sample.includes(43, -Infinity),
+ true,
+ "includes(43, -Infinity)");
+});
diff --git a/test/built-ins/TypedArray/prototype/includes/fromIndex-minus-zero.js b/test/built-ins/TypedArray/prototype/includes/fromIndex-minus-zero.js
new file mode 100644
index 000000000..e22bdf841
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/includes/fromIndex-minus-zero.js
@@ -0,0 +1,33 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%typedarray%.prototype.includes
+description: -0 fromIndex becomes 0
+info: >
+ 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.includes is a distinct function that implements the
+ same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that
+ the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length".
+
+ 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
+
+ ...
+ 5. If n ≥ 0, then
+ a. Let k be n.
+ ...
+ 7. Repeat, while k < len
+ ...
+includes: [testTypedArray.js]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample;
+
+ sample = new TA([42, 43]);
+ assert.sameValue(sample.includes(42, -0), true, "-0 [0]");
+ assert.sameValue(sample.includes(43, -0), true, "-0 [1]");
+ assert.sameValue(sample.includes(44, -0), false, "-0 [2]");
+});
diff --git a/test/built-ins/TypedArray/prototype/includes/get-length-uses-internal-arraylength.js b/test/built-ins/TypedArray/prototype/includes/get-length-uses-internal-arraylength.js
new file mode 100644
index 000000000..de73f68f8
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/includes/get-length-uses-internal-arraylength.js
@@ -0,0 +1,32 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%typedarray%.prototype.includes
+description: Get "length" uses internal ArrayLength
+info: >
+ 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.includes is a distinct function that implements the
+ same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that
+ the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length".
+
+ 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
+
+ ...
+ 2. Let len be ? ToLength(? Get(O, "length")).
+ ...
+includes: [testTypedArray.js]
+---*/
+
+Object.defineProperty(TypedArray.prototype, "length", {value: 0});
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([7]);
+
+ Object.defineProperty(TA.prototype, "length", {value: 0});
+ Object.defineProperty(sample, "length", {value: 0});
+
+ assert.sameValue(sample.includes(7), true);
+});
diff --git a/test/built-ins/TypedArray/prototype/includes/length-zero-returns-false.js b/test/built-ins/TypedArray/prototype/includes/length-zero-returns-false.js
new file mode 100644
index 000000000..86b1d2578
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/includes/length-zero-returns-false.js
@@ -0,0 +1,38 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%typedarray%.prototype.includes
+description: Returns false if length is 0
+info: >
+ 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.includes is a distinct function that implements the
+ same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that
+ the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length".
+
+ 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
+
+ ...
+ 2. Let len be ? ToLength(? Get(O, "length")).
+ 3. If len is 0, return false.
+ ...
+includes: [testTypedArray.js]
+---*/
+
+var fromIndex = {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ assert.sameValue(sample.includes(0), false, "returns false");
+ assert.sameValue(sample.includes(), false, "returns false - no arg");
+ assert.sameValue(
+ sample.includes(0, fromIndex), false,
+ "length is checked before ToInteger(fromIndex)"
+ );
+});
diff --git a/test/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js b/test/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js
new file mode 100644
index 000000000..13f72ea6b
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js
@@ -0,0 +1,33 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%typedarray%.prototype.includes
+description: Return abrupt from ToInteger(fromIndex) - using symbol
+info: >
+ 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.includes is a distinct function that implements the
+ same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that
+ the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length".
+
+ 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
+
+ ...
+ 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
+ produces the value 0.)
+ ...
+includes: [testTypedArray.js]
+features: [Symbol]
+---*/
+
+var fromIndex = Symbol("1");
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([7]);
+
+ assert.throws(TypeError, function() {
+ sample.includes(7, fromIndex);
+ });
+});
diff --git a/test/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex.js b/test/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex.js
new file mode 100644
index 000000000..906ca8392
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex.js
@@ -0,0 +1,36 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%typedarray%.prototype.includes
+description: Return abrupt from ToInteger(fromIndex)
+info: >
+ 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.includes is a distinct function that implements the
+ same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that
+ the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length".
+
+ 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
+
+ ...
+ 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
+ produces the value 0.)
+ ...
+includes: [testTypedArray.js]
+---*/
+
+var fromIndex = {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([7]);
+
+ assert.throws(Test262Error, function() {
+ sample.includes(7, fromIndex);
+ });
+});
diff --git a/test/built-ins/TypedArray/prototype/includes/samevaluezero.js b/test/built-ins/TypedArray/prototype/includes/samevaluezero.js
new file mode 100644
index 000000000..22941ce55
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/includes/samevaluezero.js
@@ -0,0 +1,43 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%typedarray%.prototype.includes
+description: search element is compared using SameValueZero
+info: >
+ 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.includes is a distinct function that implements the
+ same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that
+ the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length".
+
+ 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
+
+ ...
+ 7. Repeat, while k < len
+ a. Let elementK be the result of ? Get(O, ! ToString(k)).
+ b. If SameValueZero(searchElement, elementK) is true, return true.
+ c. Increase k by 1.
+ ...
+includes: [testTypedArray.js]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([42, 0, 1, undefined]);
+ assert.sameValue(sample.includes(), false, "no arg");
+ assert.sameValue(sample.includes(undefined), false, "undefined");
+ assert.sameValue(sample.includes("42"), false, "'42'");
+ assert.sameValue(sample.includes([42]), false, "[42]");
+ assert.sameValue(sample.includes(42.0), true, "42.0");
+ assert.sameValue(sample.includes(-0), true, "-0");
+ assert.sameValue(sample.includes(true), false, "true");
+ assert.sameValue(sample.includes(false), false, "false");
+ assert.sameValue(sample.includes(null), false, "null");
+ assert.sameValue(sample.includes(""), false, "empty string");
+});
+
+testWithTypedArrayConstructors(function(FloatArray) {
+ var sample = new FloatArray([42, 0, 1, undefined, NaN]);
+ assert.sameValue(sample.includes(NaN), true, "NaN");
+}, [Float32Array, Float64Array]);
diff --git a/test/built-ins/TypedArray/prototype/includes/search-found-returns-true.js b/test/built-ins/TypedArray/prototype/includes/search-found-returns-true.js
new file mode 100644
index 000000000..ebf4a4c30
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/includes/search-found-returns-true.js
@@ -0,0 +1,43 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%typedarray%.prototype.includes
+description: returns true for found index
+info: >
+ 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.includes is a distinct function that implements the
+ same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that
+ the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length".
+
+ 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
+
+ ...
+ 5. If n ≥ 0, then
+ a. Let k be n.
+ 6. Else n < 0,
+ a. Let k be len + n.
+ b. If k < 0, let k be 0.
+ 7. Repeat, while k < len
+ a. Let elementK be the result of ? Get(O, ! ToString(k)).
+ b. If SameValueZero(searchElement, elementK) is true, return true.
+ c. Increase k by 1.
+ ...
+includes: [testTypedArray.js]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([42, 43, 42, 41]);
+ assert.sameValue(sample.includes(42), true, "includes(42)");
+ assert.sameValue(sample.includes(43), true, "includes(43)");
+ assert.sameValue(sample.includes(43, 1), true, "includes(43, 1)");
+ assert.sameValue(sample.includes(42, 1), true, "includes(42, 1)");
+ assert.sameValue(sample.includes(42, 2), true, "includes(42, 2)");
+
+ assert.sameValue(sample.includes(42, -4), true, "includes(42, -4)");
+ assert.sameValue(sample.includes(42, -3), true, "includes(42, -3)");
+ assert.sameValue(sample.includes(42, -2), true, "includes(42, -2)");
+ assert.sameValue(sample.includes(42, -5), true, "includes(42, -5)");
+});
diff --git a/test/built-ins/TypedArray/prototype/includes/search-not-found-returns-false.js b/test/built-ins/TypedArray/prototype/includes/search-not-found-returns-false.js
new file mode 100644
index 000000000..fbf83426b
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/includes/search-not-found-returns-false.js
@@ -0,0 +1,41 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%typedarray%.prototype.includes
+description: returns false if the element is not found
+info: >
+ 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.includes is a distinct function that implements the
+ same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that
+ the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length".
+
+ 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
+
+ ...
+ 5. If n ≥ 0, then
+ a. Let k be n.
+ 6. Else n < 0,
+ a. Let k be len + n.
+ b. If k < 0, let k be 0.
+ 7. Repeat, while k < len
+ a. Let elementK be the result of ? Get(O, ! ToString(k)).
+ b. If SameValueZero(searchElement, elementK) is true, return true.
+ c. Increase k by 1.
+ 8. Return false.
+includes: [testTypedArray.js]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample;
+
+ sample = new TA([42, 43, 42, 41]);
+ assert.sameValue(sample.includes(44), false, "includes(44)");
+ assert.sameValue(sample.includes(43, 2), false, "includes(43, 2)");
+ assert.sameValue(sample.includes(42, 3), false, "includes(42, 3)");
+ assert.sameValue(sample.includes(44, -4), false, "includes(44, -4)");
+ assert.sameValue(sample.includes(44, -5), false, "includes(44, -5)");
+ assert.sameValue(sample.includes(42, -1), false, "includes(42, -1)");
+});
diff --git a/test/built-ins/TypedArray/prototype/includes/tointeger-fromindex.js b/test/built-ins/TypedArray/prototype/includes/tointeger-fromindex.js
new file mode 100644
index 000000000..496f06a6f
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/includes/tointeger-fromindex.js
@@ -0,0 +1,64 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%typedarray%.prototype.includes
+description: get the integer value from fromIndex
+info: >
+ 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.includes is a distinct function that implements the
+ same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that
+ the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length".
+
+ 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
+
+ ...
+ 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
+ produces the value 0.)
+ 5. If n ≥ 0, then
+ a. Let k be n.
+ ...
+ 7. Repeat, while k < len
+ a. Let elementK be the result of ? Get(O, ! ToString(k)).
+ b. If SameValueZero(searchElement, elementK) is true, return true.
+ c. Increase k by 1.
+ 8. Return false.
+includes: [testTypedArray.js]
+---*/
+
+var obj = {
+ valueOf: function() {
+ return 1;
+ }
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample;
+
+ sample = new TA([42, 43]);
+ assert.sameValue(sample.includes(42, "1"), false, "string [0]");
+ assert.sameValue(sample.includes(43, "1"), true, "string [1]");
+
+ assert.sameValue(sample.includes(42, true), false, "true [0]");
+ assert.sameValue(sample.includes(43, true), true, "true [1]");
+
+ assert.sameValue(sample.includes(42, false), true, "false [0]");
+ assert.sameValue(sample.includes(43, false), true, "false [1]");
+
+ assert.sameValue(sample.includes(42, NaN), true, "NaN [0]");
+ assert.sameValue(sample.includes(43, NaN), true, "NaN [1]");
+
+ assert.sameValue(sample.includes(42, null), true, "null [0]");
+ assert.sameValue(sample.includes(43, null), true, "null [1]");
+
+ assert.sameValue(sample.includes(42, undefined), true, "undefined [0]");
+ assert.sameValue(sample.includes(43, undefined), true, "undefined [1]");
+
+ assert.sameValue(sample.includes(42, null), true, "null [0]");
+ assert.sameValue(sample.includes(43, null), true, "null [1]");
+
+ assert.sameValue(sample.includes(42, obj), false, "object [0]");
+ assert.sameValue(sample.includes(43, obj), true, "object [1]");
+});