1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:07:34 +00:00

LibJS: Implement and test ArrayBuffer.prototype.resize

This commit is contained in:
ForLoveOfCats 2022-03-02 11:24:46 -05:00 committed by Linus Groh
parent b29e19c52a
commit f350c153e8
7 changed files with 118 additions and 0 deletions

View file

@ -0,0 +1,35 @@
test("length is 1", () => {
expect(ArrayBuffer.prototype.resize).toHaveLength(1);
});
test("resize up to max", () => {
let a = new ArrayBuffer(0, { maxByteLength: 10 });
a.resize(10);
expect(a.byteLength).toEqual(10);
});
test("resize less than max", () => {
let a = new ArrayBuffer(10, { maxByteLength: 10 });
a.resize(5);
expect(a.byteLength).toEqual(5);
});
test("resize with negative length", () => {
let a = new ArrayBuffer(10, { maxByteLength: 10 });
expect(() => {
a.resize(-1);
}).toThrowWithMessage(
RangeError,
"New byte length outside range supported by ArrayBuffer instance"
);
});
test("resize past max length", () => {
let a = new ArrayBuffer(10, { maxByteLength: 10 });
expect(() => {
a.resize(11);
}).toThrowWithMessage(
RangeError,
"New byte length outside range supported by ArrayBuffer instance"
);
});