mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
Add tests for %TypedArray%.prototype.includes
This commit is contained in:
parent
d3effa125f
commit
56b988883e
35
test/built-ins/TypedArray/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js
vendored
Normal file
35
test/built-ins/TypedArray/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js
vendored
Normal file
@ -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);
|
||||
});
|
43
test/built-ins/TypedArray/prototype/includes/fromIndex-infinity.js
vendored
Normal file
43
test/built-ins/TypedArray/prototype/includes/fromIndex-infinity.js
vendored
Normal file
@ -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)");
|
||||
});
|
33
test/built-ins/TypedArray/prototype/includes/fromIndex-minus-zero.js
vendored
Normal file
33
test/built-ins/TypedArray/prototype/includes/fromIndex-minus-zero.js
vendored
Normal file
@ -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]");
|
||||
});
|
32
test/built-ins/TypedArray/prototype/includes/get-length-uses-internal-arraylength.js
vendored
Normal file
32
test/built-ins/TypedArray/prototype/includes/get-length-uses-internal-arraylength.js
vendored
Normal file
@ -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);
|
||||
});
|
38
test/built-ins/TypedArray/prototype/includes/length-zero-returns-false.js
vendored
Normal file
38
test/built-ins/TypedArray/prototype/includes/length-zero-returns-false.js
vendored
Normal file
@ -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)"
|
||||
);
|
||||
});
|
33
test/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js
vendored
Normal file
33
test/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js
vendored
Normal file
@ -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);
|
||||
});
|
||||
});
|
36
test/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex.js
vendored
Normal file
36
test/built-ins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex.js
vendored
Normal file
@ -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);
|
||||
});
|
||||
});
|
43
test/built-ins/TypedArray/prototype/includes/samevaluezero.js
vendored
Normal file
43
test/built-ins/TypedArray/prototype/includes/samevaluezero.js
vendored
Normal file
@ -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]);
|
43
test/built-ins/TypedArray/prototype/includes/search-found-returns-true.js
vendored
Normal file
43
test/built-ins/TypedArray/prototype/includes/search-found-returns-true.js
vendored
Normal file
@ -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)");
|
||||
});
|
41
test/built-ins/TypedArray/prototype/includes/search-not-found-returns-false.js
vendored
Normal file
41
test/built-ins/TypedArray/prototype/includes/search-not-found-returns-false.js
vendored
Normal file
@ -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)");
|
||||
});
|
64
test/built-ins/TypedArray/prototype/includes/tointeger-fromindex.js
vendored
Normal file
64
test/built-ins/TypedArray/prototype/includes/tointeger-fromindex.js
vendored
Normal file
@ -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]");
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user