mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
Libraries: Move to Userland/Libraries/
This commit is contained in:
parent
dc28c07fa5
commit
13d7c09125
1857 changed files with 266 additions and 274 deletions
|
@ -1,68 +0,0 @@
|
|||
describe("correct behavior", () => {
|
||||
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 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);
|
||||
});
|
||||
});
|
||||
|
||||
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("invalid numeric arguments", () => {
|
||||
[1.23, Infinity, -Infinity, NaN].forEach(value => {
|
||||
expect(() => {
|
||||
BigInt(value);
|
||||
}).toThrowWithMessage(RangeError, "BigInt argument must be an integer");
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue