mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibJS: Add some tests for TypedArray.prototype.set
This commit is contained in:
parent
13c253d2ee
commit
fd8a56cdde
Notes:
sideshowbarker
2024-07-17 17:38:29 +09:00
Author: https://github.com/mjz19910 Commit: https://github.com/SerenityOS/serenity/commit/fd8a56cdde Pull-request: https://github.com/SerenityOS/serenity/pull/13019 Reviewed-by: https://github.com/Lubrsi ✅
1 changed files with 52 additions and 0 deletions
|
@ -47,4 +47,56 @@ describe("normal behavior", () => {
|
|||
expect(secondTypedArray[1]).toBe(maxUnsignedInteger);
|
||||
});
|
||||
});
|
||||
|
||||
test("set works when source is TypedArray", () => {
|
||||
function argumentTests({ array, maxUnsignedInteger }) {
|
||||
const firstTypedArray = new array(1);
|
||||
const secondTypedArray = new array([maxUnsignedInteger]);
|
||||
firstTypedArray.set(secondTypedArray, 0);
|
||||
expect(firstTypedArray[0]).toBe(maxUnsignedInteger);
|
||||
}
|
||||
|
||||
TYPED_ARRAYS.forEach(T => argumentTests(T));
|
||||
BIGINT_TYPED_ARRAYS.forEach(T => argumentTests(T));
|
||||
});
|
||||
|
||||
test("set works when source is Array", () => {
|
||||
function argumentTests({ array, maxUnsignedInteger }) {
|
||||
const firstTypedArray = new array(1);
|
||||
firstTypedArray.set([maxUnsignedInteger], 0);
|
||||
expect(firstTypedArray[0]).toBe(maxUnsignedInteger);
|
||||
}
|
||||
|
||||
TYPED_ARRAYS.forEach(T => argumentTests(T));
|
||||
BIGINT_TYPED_ARRAYS.forEach(T => argumentTests(T));
|
||||
});
|
||||
});
|
||||
|
||||
test("length is 1", () => {
|
||||
TYPED_ARRAYS.forEach(({ array: T }) => {
|
||||
expect(T.prototype.set).toHaveLength(1);
|
||||
});
|
||||
|
||||
BIGINT_TYPED_ARRAYS.forEach(({ array: T }) => {
|
||||
expect(T.prototype.set).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
function argumentErrorTests(T) {
|
||||
test(`requires at least one argument (${T.name})`, () => {
|
||||
expect(() => {
|
||||
new T().set();
|
||||
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
|
||||
});
|
||||
|
||||
test(`source array in bounds (${T.name})`, () => {
|
||||
expect(() => {
|
||||
new T().set([0]);
|
||||
}).toThrowWithMessage(RangeError, "Overflow or out of bounds in target length");
|
||||
});
|
||||
}
|
||||
|
||||
TYPED_ARRAYS.forEach(({ array: T }) => argumentErrorTests(T));
|
||||
BIGINT_TYPED_ARRAYS.forEach(({ array: T }) => argumentErrorTests(T));
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue