mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:47:35 +00:00
LibJS: Add the TypedArray.from() method
This commit is contained in:
parent
2183d01eb0
commit
fac8f9a94d
3 changed files with 114 additions and 0 deletions
|
@ -0,0 +1,28 @@
|
|||
const TYPED_ARRAYS = [
|
||||
Uint8Array,
|
||||
Uint16Array,
|
||||
Uint32Array,
|
||||
Int8Array,
|
||||
Int16Array,
|
||||
Int32Array,
|
||||
Float32Array,
|
||||
Float64Array,
|
||||
];
|
||||
|
||||
const BIGINT_TYPED_ARRAYS = [BigUint64Array, BigInt64Array];
|
||||
|
||||
test("basic functionality", () => {
|
||||
TYPED_ARRAYS.forEach(T => {
|
||||
const newTypedArray = T.from([1, 2, 3]);
|
||||
expect(newTypedArray[0]).toBe(1);
|
||||
expect(newTypedArray[1]).toBe(2);
|
||||
expect(newTypedArray[2]).toBe(3);
|
||||
});
|
||||
|
||||
BIGINT_TYPED_ARRAYS.forEach(T => {
|
||||
const newTypedArray = T.from([1n, 2n, 3n]);
|
||||
expect(newTypedArray[0]).toBe(1n);
|
||||
expect(newTypedArray[1]).toBe(2n);
|
||||
expect(newTypedArray[2]).toBe(3n);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue