mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:37:35 +00:00
LibJS: Add %TypedArray%.prototype.includes
This commit is contained in:
parent
3b9886949f
commit
da49a7a9f8
3 changed files with 89 additions and 0 deletions
|
@ -0,0 +1,44 @@
|
|||
const TYPED_ARRAYS = [
|
||||
Uint8Array,
|
||||
Uint8ClampedArray,
|
||||
Uint16Array,
|
||||
Uint32Array,
|
||||
Int8Array,
|
||||
Int16Array,
|
||||
Int32Array,
|
||||
Float32Array,
|
||||
Float64Array,
|
||||
];
|
||||
|
||||
const BIGINT_TYPED_ARRAYS = [BigUint64Array, BigInt64Array];
|
||||
|
||||
test("basic functionality", () => {
|
||||
TYPED_ARRAYS.forEach(T => {
|
||||
expect(T.prototype.includes).toHaveLength(1);
|
||||
|
||||
const typedArray = new T(3);
|
||||
typedArray[0] = 1;
|
||||
typedArray[1] = 2;
|
||||
typedArray[2] = 3;
|
||||
|
||||
expect(typedArray.includes(2)).toBe(true);
|
||||
expect(typedArray.includes(-1)).toBe(false);
|
||||
expect(typedArray.includes(Infinity)).toBe(false);
|
||||
expect(typedArray.includes(2, 2)).toBe(false);
|
||||
expect(typedArray.includes(2, -2)).toBe(true);
|
||||
});
|
||||
|
||||
BIGINT_TYPED_ARRAYS.forEach(T => {
|
||||
expect(T.prototype.includes).toHaveLength(1);
|
||||
|
||||
const typedArray = new T(3);
|
||||
typedArray[0] = 1n;
|
||||
typedArray[1] = 2n;
|
||||
typedArray[2] = 3n;
|
||||
|
||||
expect(typedArray.includes(2n)).toBe(true);
|
||||
expect(typedArray.includes(-1n)).toBe(false);
|
||||
expect(typedArray.includes(2n, 2)).toBe(false);
|
||||
expect(typedArray.includes(2n, -2)).toBe(true);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue