diff --git a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.every.js b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.every.js index 58bcea08c7..49e7f02cd7 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.every.js +++ b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.every.js @@ -12,36 +12,6 @@ const TYPED_ARRAYS = [ const BIGINT_TYPED_ARRAYS = [BigUint64Array, BigInt64Array]; -describe("errors", () => { - test("ArrayBuffer out of bounds", () => { - TYPED_ARRAYS.forEach(T => { - let arrayBuffer = new ArrayBuffer(T.BYTES_PER_ELEMENT * 2, { - maxByteLength: T.BYTES_PER_ELEMENT * 4, - }); - - let typedArray = new T(arrayBuffer, T.BYTES_PER_ELEMENT, 1); - arrayBuffer.resize(T.BYTES_PER_ELEMENT); - - expect(() => { - typedArray.every(value => value === 0); - }).toThrowWithMessage( - TypeError, - "TypedArray contains a property which references a value at an index not contained within its buffer's bounds" - ); - }); - }); -}); - -test("length is 1", () => { - TYPED_ARRAYS.forEach(T => { - expect(T.prototype.every).toHaveLength(1); - }); - - BIGINT_TYPED_ARRAYS.forEach(T => { - expect(T.prototype.every).toHaveLength(1); - }); -}); - describe("errors", () => { function errorTests(T) { test(`requires at least one argument (${T.name})`, () => { @@ -58,12 +28,38 @@ describe("errors", () => { new T().every(undefined); }).toThrowWithMessage(TypeError, "undefined is not a function"); }); + + test(`ArrayBuffer out of bounds (${T.name})`, () => { + let arrayBuffer = new ArrayBuffer(T.BYTES_PER_ELEMENT * 2, { + maxByteLength: T.BYTES_PER_ELEMENT * 4, + }); + + let typedArray = new T(arrayBuffer, T.BYTES_PER_ELEMENT, 1); + arrayBuffer.resize(T.BYTES_PER_ELEMENT); + + expect(() => { + typedArray.every(value => value === 0); + }).toThrowWithMessage( + TypeError, + "TypedArray contains a property which references a value at an index not contained within its buffer's bounds" + ); + }); } TYPED_ARRAYS.forEach(T => errorTests(T)); BIGINT_TYPED_ARRAYS.forEach(T => errorTests(T)); }); +test("length is 1", () => { + TYPED_ARRAYS.forEach(T => { + expect(T.prototype.every).toHaveLength(1); + }); + + BIGINT_TYPED_ARRAYS.forEach(T => { + expect(T.prototype.every).toHaveLength(1); + }); +}); + test("basic functionality", () => { TYPED_ARRAYS.forEach(T => { const typedArray = new T([2, 4, 6]); diff --git a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.set.js b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.set.js index 1833282712..bf2fc3e789 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.set.js +++ b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.set.js @@ -16,14 +16,26 @@ const BIGINT_TYPED_ARRAYS = [ ]; describe("errors", () => { - test("ArrayBuffer out of bounds", () => { - TYPED_ARRAYS.forEach(T => { - let arrayBuffer = new ArrayBuffer(T.array.BYTES_PER_ELEMENT * 2, { - maxByteLength: T.array.BYTES_PER_ELEMENT * 4, + 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"); + }); + + test(`ArrayBuffer out of bounds (${T.name})`, () => { + let arrayBuffer = new ArrayBuffer(T.BYTES_PER_ELEMENT * 2, { + maxByteLength: T.BYTES_PER_ELEMENT * 4, }); - let typedArray = new T.array(arrayBuffer, T.array.BYTES_PER_ELEMENT, 1); - arrayBuffer.resize(T.array.BYTES_PER_ELEMENT); + let typedArray = new T(arrayBuffer, T.BYTES_PER_ELEMENT, 1); + arrayBuffer.resize(T.BYTES_PER_ELEMENT); expect(() => { typedArray.set([0]); @@ -33,13 +45,16 @@ describe("errors", () => { ); expect(() => { - typedArray.set(new T.array()); + typedArray.set(new T()); }).toThrowWithMessage( TypeError, "TypedArray contains a property which references a value at an index not contained within its buffer's bounds" ); }); - }); + } + + TYPED_ARRAYS.forEach(({ array: T }) => argumentErrorTests(T)); + BIGINT_TYPED_ARRAYS.forEach(({ array: T }) => argumentErrorTests(T)); }); // FIXME: Write out a full test suite for this function. This currently only performs a single regression test. @@ -130,22 +145,3 @@ test("detached buffer", () => { expect(typedArray.length).toBe(0); }); }); - -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)); -}); diff --git a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.some.js b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.some.js index 63a1f25650..756179b71d 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.some.js +++ b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.some.js @@ -12,36 +12,6 @@ const TYPED_ARRAYS = [ const BIGINT_TYPED_ARRAYS = [BigUint64Array, BigInt64Array]; -describe("errors", () => { - test("ArrayBuffer out of bounds", () => { - TYPED_ARRAYS.forEach(T => { - let arrayBuffer = new ArrayBuffer(T.BYTES_PER_ELEMENT * 2, { - maxByteLength: T.BYTES_PER_ELEMENT * 4, - }); - - let typedArray = new T(arrayBuffer, T.BYTES_PER_ELEMENT, 1); - arrayBuffer.resize(T.BYTES_PER_ELEMENT); - - expect(() => { - typedArray.some(value => value === 0); - }).toThrowWithMessage( - TypeError, - "TypedArray contains a property which references a value at an index not contained within its buffer's bounds" - ); - }); - }); -}); - -test("length is 1", () => { - TYPED_ARRAYS.forEach(T => { - expect(T.prototype.some).toHaveLength(1); - }); - - BIGINT_TYPED_ARRAYS.forEach(T => { - expect(T.prototype.some).toHaveLength(1); - }); -}); - describe("errors", () => { function errorTests(T) { test(`requires at least one argument (${T.name})`, () => { @@ -58,12 +28,38 @@ describe("errors", () => { new T().some(undefined); }).toThrowWithMessage(TypeError, "undefined is not a function"); }); + + test(`ArrayBuffer out of bounds (${T.name})`, () => { + let arrayBuffer = new ArrayBuffer(T.BYTES_PER_ELEMENT * 2, { + maxByteLength: T.BYTES_PER_ELEMENT * 4, + }); + + let typedArray = new T(arrayBuffer, T.BYTES_PER_ELEMENT, 1); + arrayBuffer.resize(T.BYTES_PER_ELEMENT); + + expect(() => { + typedArray.some(value => value === 0); + }).toThrowWithMessage( + TypeError, + "TypedArray contains a property which references a value at an index not contained within its buffer's bounds" + ); + }); } TYPED_ARRAYS.forEach(T => errorTests(T)); BIGINT_TYPED_ARRAYS.forEach(T => errorTests(T)); }); +test("length is 1", () => { + TYPED_ARRAYS.forEach(T => { + expect(T.prototype.some).toHaveLength(1); + }); + + BIGINT_TYPED_ARRAYS.forEach(T => { + expect(T.prototype.some).toHaveLength(1); + }); +}); + test("basic functionality", () => { TYPED_ARRAYS.forEach(T => { const typedArray = new T([2, 4, 6]); diff --git a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.toSorted.js b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.toSorted.js index 3e13c97922..69ca98b1b8 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.toSorted.js +++ b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.toSorted.js @@ -13,6 +13,38 @@ const TYPED_ARRAYS = [ const BIGINT_TYPED_ARRAYS = [BigUint64Array, BigInt64Array]; describe("errors", () => { + test("null or undefined this value", () => { + TYPED_ARRAYS.forEach(T => { + expect(() => { + T.prototype.toSorted.call(); + }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); + + expect(() => { + T.prototype.toSorted.call(undefined); + }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); + + expect(() => { + T.prototype.toSorted.call(null); + }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); + }); + + BIGINT_TYPED_ARRAYS.forEach(T => {}); + }); + + test("invalid compare function", () => { + TYPED_ARRAYS.forEach(T => { + expect(() => { + new T([]).toSorted("foo"); + }).toThrowWithMessage(TypeError, "foo is not a function"); + }); + + BIGINT_TYPED_ARRAYS.forEach(T => { + expect(() => { + new T([]).toSorted("foo"); + }).toThrowWithMessage(TypeError, "foo is not a function"); + }); + }); + test("ArrayBuffer out of bounds", () => { TYPED_ARRAYS.forEach(T => { let arrayBuffer = new ArrayBuffer(T.BYTES_PER_ELEMENT * 2, { @@ -90,37 +122,3 @@ test("detached buffer", () => { expect(sortedTypedArray[2]).toBe(3); }); }); - -describe("errors", () => { - test("null or undefined this value", () => { - TYPED_ARRAYS.forEach(T => { - expect(() => { - T.prototype.toSorted.call(); - }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); - - expect(() => { - T.prototype.toSorted.call(undefined); - }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); - - expect(() => { - T.prototype.toSorted.call(null); - }).toThrowWithMessage(TypeError, "ToObject on null or undefined"); - }); - - BIGINT_TYPED_ARRAYS.forEach(T => {}); - }); - - test("invalid compare function", () => { - TYPED_ARRAYS.forEach(T => { - expect(() => { - new T([]).toSorted("foo"); - }).toThrowWithMessage(TypeError, "foo is not a function"); - }); - - BIGINT_TYPED_ARRAYS.forEach(T => { - expect(() => { - new T([]).toSorted("foo"); - }).toThrowWithMessage(TypeError, "foo is not a function"); - }); - }); -});