1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 17:47:45 +00:00

LibJS: Start implementing Temporal.PlainMonthDay

This commit adds the PlainMonthDay object itself, its constructor and
prototype (currently empty), and the CreateTemporalMonthDay abstract
operations.
This commit is contained in:
Linus Groh 2021-08-14 23:54:24 +01:00
parent 301d622b46
commit be07e2e91b
12 changed files with 344 additions and 0 deletions

View file

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