mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:17:35 +00:00
LibJS: Consolidate duplicate "errors" sections in LibJS tests
A couple of duplicate sections were errantly added in commit 9258d7b98a
.
This commit is contained in:
parent
507a5d8a07
commit
cabd599c8b
4 changed files with 107 additions and 121 deletions
|
@ -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]);
|
||||
|
|
|
@ -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));
|
||||
});
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue