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

LibJS: Start implementing Temporal.PlainDate

This commit adds the PlainDate object itself, its constructor and
prototype (currently empty), and several required abstract operations.
This commit is contained in:
Idan Horowitz 2021-07-19 00:29:26 +03:00 committed by Linus Groh
parent ff6ca0f02d
commit cc00ccec41
19 changed files with 465 additions and 5 deletions

View file

@ -0,0 +1,53 @@
describe("errors", () => {
test("called without new", () => {
expect(() => {
Temporal.PlainDate();
}).toThrowWithMessage(
TypeError,
"Temporal.PlainDate constructor must be called with 'new'"
);
});
test("cannot pass Infinity", () => {
expect(() => {
new Temporal.PlainDate(Infinity);
}).toThrowWithMessage(RangeError, "Invalid plain date");
expect(() => {
new Temporal.PlainDate(0, Infinity);
}).toThrowWithMessage(RangeError, "Invalid plain date");
expect(() => {
new Temporal.PlainDate(0, 0, Infinity);
}).toThrowWithMessage(RangeError, "Invalid plain date");
expect(() => {
new Temporal.PlainDate(-Infinity);
}).toThrowWithMessage(RangeError, "Invalid plain date");
expect(() => {
new Temporal.PlainDate(0, -Infinity);
}).toThrowWithMessage(RangeError, "Invalid plain date");
expect(() => {
new Temporal.PlainDate(0, 0, -Infinity);
}).toThrowWithMessage(RangeError, "Invalid plain date");
});
test("cannot pass invalid ISO month/day", () => {
expect(() => {
new Temporal.PlainDate(0, 0, 1);
}).toThrowWithMessage(RangeError, "Invalid plain date");
expect(() => {
new Temporal.PlainDate(0, 1, 0);
}).toThrowWithMessage(RangeError, "Invalid plain date");
});
});
describe("normal behavior", () => {
test("length is 0", () => {
expect(Temporal.PlainDate).toHaveLength(0);
});
test("basic functionality", () => {
const plainDate = new Temporal.PlainDate(2021, 7, 19);
expect(typeof plainDate).toBe("object");
expect(plainDate).toBeInstanceOf(Temporal.PlainDate);
expect(Object.getPrototypeOf(plainDate)).toBe(Temporal.PlainDate.prototype);
});
});