mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-06 01:26:22 +00:00
LibJS: Implement the Temporal.PlainMonthDay constructor
And the simple Temporal.PlainMonthDay.prototype getters, so that the constructed Temporal.PlainMonthDay may actually be validated.
This commit is contained in:
parent
b3b968bed9
commit
1a386e78c3
Notes:
github-actions[bot]
2024-11-22 00:25:44 +00:00
Author: https://github.com/trflynn89
Commit: 1a386e78c3
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2471
31 changed files with 2515 additions and 4 deletions
|
@ -0,0 +1,66 @@
|
|||
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, undefined, 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, undefined, -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");
|
||||
});
|
||||
|
||||
test("not within iso date time limit", () => {
|
||||
expect(() => {
|
||||
new Temporal.PlainMonthDay(9, 30, "iso8601", 999_999_999_999_999);
|
||||
}).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);
|
||||
});
|
||||
|
||||
// FIXME: Re-implement this test with Temporal.PlainMonthDay.prototype.toString({ calendarName: "always" }).
|
||||
// test("default reference year is 1972", () => {
|
||||
// const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
|
||||
// const fields = plainMonthDay.getISOFields();
|
||||
// expect(fields.isoYear).toBe(1972);
|
||||
// });
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue