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

LibJS: Indent tests with 4 spaces instead of 2

This commit is contained in:
Matthew Olsson 2020-07-06 07:37:45 -07:00 committed by Andreas Kling
parent 15de2eda2b
commit 1ef573eb30
261 changed files with 8536 additions and 8497 deletions

View file

@ -1,68 +1,68 @@
describe("correct behavior", () => {
test("basic functionality", () => {
expect(BigInt).toHaveLength(1);
expect(BigInt.name).toBe("BigInt");
});
test("basic functionality", () => {
expect(BigInt).toHaveLength(1);
expect(BigInt.name).toBe("BigInt");
});
test("constructor with numbers", () => {
expect(BigInt(0)).toBe(0n);
expect(BigInt(1)).toBe(1n);
expect(BigInt(+1)).toBe(1n);
expect(BigInt(-1)).toBe(-1n);
expect(BigInt(123n)).toBe(123n);
});
test("constructor with numbers", () => {
expect(BigInt(0)).toBe(0n);
expect(BigInt(1)).toBe(1n);
expect(BigInt(+1)).toBe(1n);
expect(BigInt(-1)).toBe(-1n);
expect(BigInt(123n)).toBe(123n);
});
test("constructor with strings", () => {
expect(BigInt("")).toBe(0n);
expect(BigInt("0")).toBe(0n);
expect(BigInt("1")).toBe(1n);
expect(BigInt("+1")).toBe(1n);
expect(BigInt("-1")).toBe(-1n);
expect(BigInt("-1")).toBe(-1n);
expect(BigInt("42")).toBe(42n);
expect(BigInt(" \n 00100 \n ")).toBe(100n);
expect(BigInt("3323214327642987348732109829832143298746432437532197321")).toBe(
3323214327642987348732109829832143298746432437532197321n
);
});
test("constructor with strings", () => {
expect(BigInt("")).toBe(0n);
expect(BigInt("0")).toBe(0n);
expect(BigInt("1")).toBe(1n);
expect(BigInt("+1")).toBe(1n);
expect(BigInt("-1")).toBe(-1n);
expect(BigInt("-1")).toBe(-1n);
expect(BigInt("42")).toBe(42n);
expect(BigInt(" \n 00100 \n ")).toBe(100n);
expect(BigInt("3323214327642987348732109829832143298746432437532197321")).toBe(
3323214327642987348732109829832143298746432437532197321n
);
});
test("constructor with objects", () => {
expect(BigInt([])).toBe(0n);
});
test("constructor with objects", () => {
expect(BigInt([])).toBe(0n);
});
});
describe("errors", () => {
test('cannot be constructed with "new"', () => {
expect(() => {
new BigInt();
}).toThrowWithMessage(TypeError, "BigInt is not a constructor");
});
test("invalid arguments", () => {
expect(() => {
BigInt(null);
}).toThrowWithMessage(TypeError, "Cannot convert null to BigInt");
expect(() => {
BigInt(undefined);
}).toThrowWithMessage(TypeError, "Cannot convert undefined to BigInt");
expect(() => {
BigInt(Symbol());
}).toThrowWithMessage(TypeError, "Cannot convert symbol to BigInt");
["foo", "123n", "1+1", {}, function () {}].forEach(value => {
expect(() => {
BigInt(value);
}).toThrowWithMessage(SyntaxError, `Invalid value for BigInt: ${value}`);
test('cannot be constructed with "new"', () => {
expect(() => {
new BigInt();
}).toThrowWithMessage(TypeError, "BigInt is not a constructor");
});
});
test("invalid numeric arguments", () => {
[1.23, Infinity, -Infinity, NaN].forEach(value => {
expect(() => {
BigInt(value);
}).toThrowWithMessage(RangeError, "BigInt argument must be an integer");
test("invalid arguments", () => {
expect(() => {
BigInt(null);
}).toThrowWithMessage(TypeError, "Cannot convert null to BigInt");
expect(() => {
BigInt(undefined);
}).toThrowWithMessage(TypeError, "Cannot convert undefined to BigInt");
expect(() => {
BigInt(Symbol());
}).toThrowWithMessage(TypeError, "Cannot convert symbol to BigInt");
["foo", "123n", "1+1", {}, function () {}].forEach(value => {
expect(() => {
BigInt(value);
}).toThrowWithMessage(SyntaxError, `Invalid value for BigInt: ${value}`);
});
});
test("invalid numeric arguments", () => {
[1.23, Infinity, -Infinity, NaN].forEach(value => {
expect(() => {
BigInt(value);
}).toThrowWithMessage(RangeError, "BigInt argument must be an integer");
});
});
});
});

View file

@ -1,10 +1,10 @@
test("basic functionality", () => {
expect(BigInt.prototype.toLocaleString).toHaveLength(0);
expect(BigInt(123).toLocaleString()).toBe("123");
expect(BigInt.prototype.toLocaleString).toHaveLength(0);
expect(BigInt(123).toLocaleString()).toBe("123");
});
test("calling with non-BigInt |this|", () => {
expect(() => {
BigInt.prototype.toLocaleString.call("foo");
}).toThrowWithMessage(TypeError, "Not a BigInt object");
expect(() => {
BigInt.prototype.toLocaleString.call("foo");
}).toThrowWithMessage(TypeError, "Not a BigInt object");
});

View file

@ -1,10 +1,10 @@
test("basic functionality", () => {
expect(BigInt.prototype.toString).toHaveLength(0);
expect(BigInt(123).toString()).toBe("123");
expect(BigInt.prototype.toString).toHaveLength(0);
expect(BigInt(123).toString()).toBe("123");
});
test("calling with non-BigInt |this|", () => {
expect(() => {
BigInt.prototype.toString.call("foo");
}).toThrowWithMessage(TypeError, "Not a BigInt object");
expect(() => {
BigInt.prototype.toString.call("foo");
}).toThrowWithMessage(TypeError, "Not a BigInt object");
});

View file

@ -1,12 +1,12 @@
test("basic functionality", () => {
expect(BigInt.prototype.valueOf).toHaveLength(0);
expect(typeof BigInt(123).valueOf()).toBe("bigint");
// FIXME: Uncomment once we support Object() with argument
// expect(typeof Object(123n).valueOf()).toBe("bigint");
expect(BigInt.prototype.valueOf).toHaveLength(0);
expect(typeof BigInt(123).valueOf()).toBe("bigint");
// FIXME: Uncomment once we support Object() with argument
// expect(typeof Object(123n).valueOf()).toBe("bigint");
});
test("calling with non-BigInt |this|", () => {
expect(() => {
BigInt.prototype.valueOf.call("foo");
}).toThrowWithMessage(TypeError, "Not a BigInt object");
expect(() => {
BigInt.prototype.valueOf.call("foo");
}).toThrowWithMessage(TypeError, "Not a BigInt object");
});

View file

@ -1,80 +1,80 @@
describe("correct behavior", () => {
test("typeof bigint", () => {
expect(typeof 1n).toBe("bigint");
});
test("typeof bigint", () => {
expect(typeof 1n).toBe("bigint");
});
test("bigint string coersion", () => {
expect("" + 123n).toBe("123");
});
test("bigint string coersion", () => {
expect("" + 123n).toBe("123");
});
test("arithmetic operators", () => {
let bigint = 123n;
expect(-bigint).toBe(-123n);
test("arithmetic operators", () => {
let bigint = 123n;
expect(-bigint).toBe(-123n);
expect(12n + 34n).toBe(46n);
expect(12n - 34n).toBe(-22n);
expect(8n * 12n).toBe(96n);
expect(123n / 10n).toBe(12n);
expect(2n ** 3n).toBe(8n);
expect(5n % 3n).toBe(2n);
expect(
45977665298704210987n +
(714320987142450987412098743217984576n / 4598741987421098765327980n) * 987498743n
).toBe(199365500239020623962n);
});
expect(12n + 34n).toBe(46n);
expect(12n - 34n).toBe(-22n);
expect(8n * 12n).toBe(96n);
expect(123n / 10n).toBe(12n);
expect(2n ** 3n).toBe(8n);
expect(5n % 3n).toBe(2n);
expect(
45977665298704210987n +
(714320987142450987412098743217984576n / 4598741987421098765327980n) * 987498743n
).toBe(199365500239020623962n);
});
test("bitwise operators", () => {
expect(12n & 5n).toBe(4n);
expect(1n | 2n).toBe(3n);
expect(5n ^ 3n).toBe(6n);
expect(~1n).toBe(-2n);
});
test("bitwise operators", () => {
expect(12n & 5n).toBe(4n);
expect(1n | 2n).toBe(3n);
expect(5n ^ 3n).toBe(6n);
expect(~1n).toBe(-2n);
});
test("increment operators", () => {
let bigint = 1n;
expect(bigint++).toBe(1n);
expect(bigint).toBe(2n);
expect(bigint--).toBe(2n);
expect(bigint).toBe(1n);
expect(++bigint).toBe(2n);
expect(bigint).toBe(2n);
expect(--bigint).toBe(1n);
expect(bigint).toBe(1n);
});
test("increment operators", () => {
let bigint = 1n;
expect(bigint++).toBe(1n);
expect(bigint).toBe(2n);
expect(bigint--).toBe(2n);
expect(bigint).toBe(1n);
expect(++bigint).toBe(2n);
expect(bigint).toBe(2n);
expect(--bigint).toBe(1n);
expect(bigint).toBe(1n);
});
test("weak equality operators", () => {
expect(1n == 1n).toBeTrue();
expect(1n == 1).toBeTrue();
expect(1 == 1n).toBeTrue();
expect(1n == 1.23).toBeFalse();
expect(1.23 == 1n).toBeFalse();
test("weak equality operators", () => {
expect(1n == 1n).toBeTrue();
expect(1n == 1).toBeTrue();
expect(1 == 1n).toBeTrue();
expect(1n == 1.23).toBeFalse();
expect(1.23 == 1n).toBeFalse();
expect(1n != 1n).toBeFalse();
expect(1n != 1).toBeFalse();
expect(1 != 1n).toBeFalse();
expect(1n != 1.23).toBeTrue();
expect(1.23 != 1n).toBeTrue();
});
expect(1n != 1n).toBeFalse();
expect(1n != 1).toBeFalse();
expect(1 != 1n).toBeFalse();
expect(1n != 1.23).toBeTrue();
expect(1.23 != 1n).toBeTrue();
});
test("strong equality operators", () => {
expect(1n === 1n).toBeTrue();
expect(1n === 1).toBeFalse();
expect(1 === 1n).toBeFalse();
expect(1n === 1.23).toBeFalse();
expect(1.23 === 1n).toBeFalse();
test("strong equality operators", () => {
expect(1n === 1n).toBeTrue();
expect(1n === 1).toBeFalse();
expect(1 === 1n).toBeFalse();
expect(1n === 1.23).toBeFalse();
expect(1.23 === 1n).toBeFalse();
expect(1n !== 1n).toBeFalse();
expect(1n !== 1).toBeTrue();
expect(1 !== 1n).toBeTrue();
expect(1n !== 1.23).toBeTrue();
expect(1.23 !== 1n).toBeTrue();
});
expect(1n !== 1n).toBeFalse();
expect(1n !== 1).toBeTrue();
expect(1 !== 1n).toBeTrue();
expect(1n !== 1.23).toBeTrue();
expect(1.23 !== 1n).toBeTrue();
});
});
describe("errors", () => {
test("conversion to number", () => {
expect(() => {
+123n;
}).toThrowWithMessage(TypeError, "Cannot convert BigInt to number");
});
test("conversion to number", () => {
expect(() => {
+123n;
}).toThrowWithMessage(TypeError, "Cannot convert BigInt to number");
});
});

View file

@ -1,31 +1,31 @@
const doTest = (operatorName, executeOperation) => {
[1, null, undefined].forEach(value => {
const messageSuffix = operatorName === "unsigned right-shift" ? "" : " and other type";
[1, null, undefined].forEach(value => {
const messageSuffix = operatorName === "unsigned right-shift" ? "" : " and other type";
expect(() => {
executeOperation(1n, value);
}).toThrowWithMessage(
TypeError,
`Cannot use ${operatorName} operator with BigInt${messageSuffix}`
);
});
expect(() => {
executeOperation(1n, value);
}).toThrowWithMessage(
TypeError,
`Cannot use ${operatorName} operator with BigInt${messageSuffix}`
);
});
};
[
["addition", (a, b) => a + b],
["subtraction", (a, b) => a - b],
["multiplication", (a, b) => a * b],
["division", (a, b) => a / b],
["modulo", (a, b) => a % b],
["exponentiation", (a, b) => a ** b],
["bitwise OR", (a, b) => a | b],
["bitwise AND", (a, b) => a & b],
["bitwise XOR", (a, b) => a ^ b],
["left-shift", (a, b) => a << b],
["right-shift", (a, b) => a >> b],
["unsigned right-shift", (a, b) => a >>> b],
["addition", (a, b) => a + b],
["subtraction", (a, b) => a - b],
["multiplication", (a, b) => a * b],
["division", (a, b) => a / b],
["modulo", (a, b) => a % b],
["exponentiation", (a, b) => a ** b],
["bitwise OR", (a, b) => a | b],
["bitwise AND", (a, b) => a & b],
["bitwise XOR", (a, b) => a ^ b],
["left-shift", (a, b) => a << b],
["right-shift", (a, b) => a >> b],
["unsigned right-shift", (a, b) => a >>> b],
].forEach(testCase => {
test(`using ${testCase[0]} operator with BigInt and other type`, () => {
doTest(testCase[0], testCase[1]);
});
test(`using ${testCase[0]} operator with BigInt and other type`, () => {
doTest(testCase[0], testCase[1]);
});
});