summaryrefslogtreecommitdiff
path: root/test/built-ins
diff options
context:
space:
mode:
authorLeonardo Balter <leonardo.balter@gmail.com>2016-04-19 17:24:47 -0400
committerGorkem Yakin <goyakin@microsoft.com>2016-04-25 10:31:38 -0700
commitd46b0b186012556a2e1e3abd81d3181c7c5d54c2 (patch)
tree7f2b762165777e0fa5d56e001221ccc9d4383f38 /test/built-ins
parentcf68c3be91bd338ebc2e6b5122775a884516d993 (diff)
downloadqtdeclarative-testsuites-d46b0b186012556a2e1e3abd81d3181c7c5d54c2.tar.gz
Add tests for TypedArrays indexOf
Diffstat (limited to 'test/built-ins')
-rw-r--r--test/built-ins/TypedArray/prototype/indexOf/fromIndex-equal-or-greater-length-returns-minus-one.js29
-rw-r--r--test/built-ins/TypedArray/prototype/indexOf/fromIndex-infinity.js38
-rw-r--r--test/built-ins/TypedArray/prototype/indexOf/fromIndex-minus-zero.js29
-rw-r--r--test/built-ins/TypedArray/prototype/indexOf/get-length-uses-internal-arraylength.js31
-rw-r--r--test/built-ins/TypedArray/prototype/indexOf/length-zero-returns-minus-one.js36
-rw-r--r--test/built-ins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex-symbol.js32
-rw-r--r--test/built-ins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex.js35
-rw-r--r--test/built-ins/TypedArray/prototype/indexOf/search-found-returns-index.js45
-rw-r--r--test/built-ins/TypedArray/prototype/indexOf/search-not-found-returns-minus-one.js37
-rw-r--r--test/built-ins/TypedArray/prototype/indexOf/strict-comparison.js40
-rw-r--r--test/built-ins/TypedArray/prototype/indexOf/tointeger-fromindex.js56
11 files changed, 408 insertions, 0 deletions
diff --git a/test/built-ins/TypedArray/prototype/indexOf/fromIndex-equal-or-greater-length-returns-minus-one.js b/test/built-ins/TypedArray/prototype/indexOf/fromIndex-equal-or-greater-length-returns-minus-one.js
new file mode 100644
index 000000000..116c8b34a
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/indexOf/fromIndex-equal-or-greater-length-returns-minus-one.js
@@ -0,0 +1,29 @@
+// 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.indexof
+description: Return -1 if fromIndex >= ArrayLength
+info: >
+ 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.indexOf is a distinct function that implements the same
+ algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
+ this object's [[ArrayLength]] internal slot is accessed in place of performing
+ a [[Get]] of "length".
+
+ 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
+
+ ...
+ 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
+ produces the value 0.)
+ ...
+includes: [testTypedArray.js]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample;
+
+ sample = new TA(42);
+ assert.sameValue(sample.indexOf(0, 42), -1);
+ assert.sameValue(sample.indexOf(0, 43), -1);
+});
diff --git a/test/built-ins/TypedArray/prototype/indexOf/fromIndex-infinity.js b/test/built-ins/TypedArray/prototype/indexOf/fromIndex-infinity.js
new file mode 100644
index 000000000..2cd2f2991
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/indexOf/fromIndex-infinity.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.indexof
+description: handle Infinity values for fromIndex
+info: >
+ 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.indexOf is a distinct function that implements the same
+ algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
+ this object's [[ArrayLength]] internal slot is accessed in place of performing
+ a [[Get]] of "length".
+
+ 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
+
+ ...
+ 6. If n ≥ 0, then
+ a. If n is -0, let k be +0; else let k be n.
+ 7. Else n < 0,
+ a. Let k be len + n.
+ b. If k < 0, let k be 0.
+ 8. Repeat, while k < len
+ a. Let kPresent be ? HasProperty(O, ! ToString(k)).
+ b. If kPresent is true, then
+ i. Let elementK be ? Get(O, ! ToString(k)).
+ ii. Let same be the result of performing Strict Equality Comparison
+ searchElement === elementK.
+ iii. If same is true, return k.
+ ...
+includes: [testTypedArray.js]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([42, 43, 43, 41]);
+
+ assert.sameValue(sample.indexOf(43, Infinity), -1, "indexOf(43, Infinity)");
+ assert.sameValue(sample.indexOf(43, -Infinity), 1, "indexOf(43, -Infinity)");
+});
diff --git a/test/built-ins/TypedArray/prototype/indexOf/fromIndex-minus-zero.js b/test/built-ins/TypedArray/prototype/indexOf/fromIndex-minus-zero.js
new file mode 100644
index 000000000..aeaea5c6e
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/indexOf/fromIndex-minus-zero.js
@@ -0,0 +1,29 @@
+// 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.indexof
+description: -0 fromIndex becomes 0
+info: >
+ 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.indexOf is a distinct function that implements the same
+ algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
+ this object's [[ArrayLength]] internal slot is accessed in place of performing
+ a [[Get]] of "length".
+
+ 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
+
+ ...
+ 6. If n ≥ 0, then
+ a. If n is -0, let k be +0; else let k be n.
+ ...
+includes: [testTypedArray.js]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample;
+
+ sample = new TA([42, 43]);
+ assert.sameValue(sample.indexOf(42, -0), 0, "-0 [0]");
+ assert.sameValue(sample.indexOf(43, -0), 1, "-0 [1]");
+});
diff --git a/test/built-ins/TypedArray/prototype/indexOf/get-length-uses-internal-arraylength.js b/test/built-ins/TypedArray/prototype/indexOf/get-length-uses-internal-arraylength.js
new file mode 100644
index 000000000..e3095ab34
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/indexOf/get-length-uses-internal-arraylength.js
@@ -0,0 +1,31 @@
+// 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.indexof
+description: Get "length" uses internal ArrayLength
+info: >
+ 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.indexOf is a distinct function that implements the same
+ algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
+ this object's [[ArrayLength]] internal slot is accessed in place of performing
+ a [[Get]] of "length".
+
+ 22.1.3.12 Array.prototype.indexOf ( 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.indexOf(7), 0);
+});
diff --git a/test/built-ins/TypedArray/prototype/indexOf/length-zero-returns-minus-one.js b/test/built-ins/TypedArray/prototype/indexOf/length-zero-returns-minus-one.js
new file mode 100644
index 000000000..98c93d567
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/indexOf/length-zero-returns-minus-one.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.indexof
+description: Returns -1 if length is 0
+info: >
+ 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.indexOf is a distinct function that implements the same
+ algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
+ this object's [[ArrayLength]] internal slot is accessed in place of performing
+ a [[Get]] of "length".
+
+ 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
+
+ ...
+ 2. Let len be ? ToLength(? Get(O, "length")).
+ 3. If len is 0, return -1.
+ ...
+includes: [testTypedArray.js]
+---*/
+
+var fromIndex = {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ assert.sameValue(sample.indexOf(0), -1, "returns -1");
+ assert.sameValue(
+ sample.indexOf(0, fromIndex), -1,
+ "length is checked before ToInteger(fromIndex)"
+ );
+});
diff --git a/test/built-ins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex-symbol.js b/test/built-ins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex-symbol.js
new file mode 100644
index 000000000..a12260b21
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex-symbol.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.indexof
+description: Return abrupt from ToInteger(fromIndex) - using symbol
+info: >
+ 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.indexOf is a distinct function that implements the same
+ algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
+ this object's [[ArrayLength]] internal slot is accessed in place of performing
+ a [[Get]] of "length".
+
+ 22.1.3.12 Array.prototype.indexOf ( 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(1);
+
+ assert.throws(TypeError, function() {
+ sample.indexOf(7, fromIndex);
+ })
+});
diff --git a/test/built-ins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex.js b/test/built-ins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex.js
new file mode 100644
index 000000000..d26490153
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex.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.indexof
+description: Return abrupt from ToInteger(fromIndex)
+info: >
+ 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.indexOf is a distinct function that implements the same
+ algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
+ this object's [[ArrayLength]] internal slot is accessed in place of performing
+ a [[Get]] of "length".
+
+ 22.1.3.12 Array.prototype.indexOf ( 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(1);
+
+ assert.throws(Test262Error, function() {
+ sample.indexOf(7, fromIndex);
+ })
+});
diff --git a/test/built-ins/TypedArray/prototype/indexOf/search-found-returns-index.js b/test/built-ins/TypedArray/prototype/indexOf/search-found-returns-index.js
new file mode 100644
index 000000000..416af33f3
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/indexOf/search-found-returns-index.js
@@ -0,0 +1,45 @@
+// 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.indexof
+description: returns index for the first found element
+info: >
+ 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.indexOf is a distinct function that implements the same
+ algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
+ this object's [[ArrayLength]] internal slot is accessed in place of performing
+ a [[Get]] of "length".
+
+ 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
+
+ ...
+ 6. If n ≥ 0, then
+ a. If n is -0, let k be +0; else let k be n.
+ 7. Else n < 0,
+ a. Let k be len + n.
+ b. If k < 0, let k be 0.
+ 8. Repeat, while k < len
+ a. Let kPresent be ? HasProperty(O, ! ToString(k)).
+ b. If kPresent is true, then
+ i. Let elementK be ? Get(O, ! ToString(k)).
+ ii. Let same be the result of performing Strict Equality Comparison
+ searchElement === elementK.
+ iii. If same is true, return k.
+ ...
+includes: [testTypedArray.js]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([42, 43, 42, 41]);
+ assert.sameValue(sample.indexOf(42), 0, "indexOf(42)");
+ assert.sameValue(sample.indexOf(43), 1, "indexOf(43)");
+ assert.sameValue(sample.indexOf(43, 1), 1, "indexOf(43, 1)");
+ assert.sameValue(sample.indexOf(42, 1), 2, "indexOf(42, 1)");
+ assert.sameValue(sample.indexOf(42, 2), 2, "indexOf(42, 2)");
+
+ assert.sameValue(sample.indexOf(42, -4), 0, "indexOf(42, -4)");
+ assert.sameValue(sample.indexOf(42, -3), 2, "indexOf(42, -3)");
+ assert.sameValue(sample.indexOf(42, -2), 2, "indexOf(42, -2)");
+ assert.sameValue(sample.indexOf(42, -5), 0, "indexOf(42, -5)");
+});
diff --git a/test/built-ins/TypedArray/prototype/indexOf/search-not-found-returns-minus-one.js b/test/built-ins/TypedArray/prototype/indexOf/search-not-found-returns-minus-one.js
new file mode 100644
index 000000000..e1f2c8d1a
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/indexOf/search-not-found-returns-minus-one.js
@@ -0,0 +1,37 @@
+// 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.indexof
+description: returns -1 if the element if not found
+info: >
+ 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.indexOf is a distinct function that implements the same
+ algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
+ this object's [[ArrayLength]] internal slot is accessed in place of performing
+ a [[Get]] of "length".
+
+ 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
+
+ ...
+ 6. If n ≥ 0, then
+ a. If n is -0, let k be +0; else let k be n.
+ 7. Else n < 0,
+ a. Let k be len + n.
+ b. If k < 0, let k be 0.
+ ...
+ 9. Return -1.
+includes: [testTypedArray.js]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample;
+
+ sample = new TA([42, 43, 42, 41]);
+ assert.sameValue(sample.indexOf(44), -1, "indexOf(44)");
+ assert.sameValue(sample.indexOf(43, 2), -1, "indexOf(43, 2)");
+ assert.sameValue(sample.indexOf(42, 3), -1, "indexOf(42, 3)");
+ assert.sameValue(sample.indexOf(44, -4), -1, "indexOf(44, -4)");
+ assert.sameValue(sample.indexOf(44, -5), -1, "indexOf(44, -5)");
+ assert.sameValue(sample.indexOf(42, -1), -1, "indexOf(42, -1)");
+});
diff --git a/test/built-ins/TypedArray/prototype/indexOf/strict-comparison.js b/test/built-ins/TypedArray/prototype/indexOf/strict-comparison.js
new file mode 100644
index 000000000..76e746706
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/indexOf/strict-comparison.js
@@ -0,0 +1,40 @@
+// 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.indexof
+description: search element is compared using strict comparing (===)
+info: >
+ 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.indexOf is a distinct function that implements the same
+ algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
+ this object's [[ArrayLength]] internal slot is accessed in place of performing
+ a [[Get]] of "length".
+
+ 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
+
+ ...
+ 8. Repeat, while k < len
+ ...
+ b. If kPresent is true, then
+ i. Let elementK be ? Get(O, ! ToString(k)).
+ ii. Let same be the result of performing Strict Equality Comparison
+ searchElement === elementK.
+ iii. If same is true, return k.
+ ...
+includes: [testTypedArray.js]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([42, 0, 1, undefined, NaN]);
+ assert.sameValue(sample.indexOf("42"), -1, "'42'");
+ assert.sameValue(sample.indexOf([42]), -1, "[42]");
+ assert.sameValue(sample.indexOf(42.0), 0, "42.0");
+ assert.sameValue(sample.indexOf(-0), 1, "-0");
+ assert.sameValue(sample.indexOf(true), -1, "true");
+ assert.sameValue(sample.indexOf(false), -1, "false");
+ assert.sameValue(sample.indexOf(NaN), -1, "NaN === NaN is false");
+ assert.sameValue(sample.indexOf(null), -1, "null");
+ assert.sameValue(sample.indexOf(undefined), -1, "undefined");
+ assert.sameValue(sample.indexOf(""), -1, "empty string");
+});
diff --git a/test/built-ins/TypedArray/prototype/indexOf/tointeger-fromindex.js b/test/built-ins/TypedArray/prototype/indexOf/tointeger-fromindex.js
new file mode 100644
index 000000000..e80ddd1d1
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/indexOf/tointeger-fromindex.js
@@ -0,0 +1,56 @@
+// 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.indexof
+description: Return -1 if fromIndex >= ArrayLength - converted values
+info: >
+ 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
+
+ %TypedArray%.prototype.indexOf is a distinct function that implements the same
+ algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
+ this object's [[ArrayLength]] internal slot is accessed in place of performing
+ a [[Get]] of "length".
+
+ 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
+
+ ...
+ 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
+ produces the value 0.)
+ ...
+includes: [testTypedArray.js]
+---*/
+
+var obj = {
+ valueOf: function() {
+ return 1;
+ }
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample;
+
+ sample = new TA([42, 43]);
+ assert.sameValue(sample.indexOf(42, "1"), -1, "string [0]");
+ assert.sameValue(sample.indexOf(43, "1"), 1, "string [1]");
+
+ assert.sameValue(sample.indexOf(42, true), -1, "true [0]");
+ assert.sameValue(sample.indexOf(43, true), 1, "true [1]");
+
+ assert.sameValue(sample.indexOf(42, false), 0, "false [0]");
+ assert.sameValue(sample.indexOf(43, false), 1, "false [1]");
+
+ assert.sameValue(sample.indexOf(42, NaN), 0, "NaN [0]");
+ assert.sameValue(sample.indexOf(43, NaN), 1, "NaN [1]");
+
+ assert.sameValue(sample.indexOf(42, null), 0, "null [0]");
+ assert.sameValue(sample.indexOf(43, null), 1, "null [1]");
+
+ assert.sameValue(sample.indexOf(42, undefined), 0, "undefined [0]");
+ assert.sameValue(sample.indexOf(43, undefined), 1, "undefined [1]");
+
+ assert.sameValue(sample.indexOf(42, null), 0, "null [0]");
+ assert.sameValue(sample.indexOf(43, null), 1, "null [1]");
+
+ assert.sameValue(sample.indexOf(42, obj), -1, "object [0]");
+ assert.sameValue(sample.indexOf(43, obj), 1, "object [1]");
+});