mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-02 15:46:33 +00:00
LibJS: Implement the Temporal.PlainYearMonth constructor
And the simple Temporal.PlainYearMonth.prototype getters, so that the constructed Temporal.PlainYearMonth may actually be validated.
This commit is contained in:
parent
1c733993e0
commit
b68d67693e
Notes:
github-actions[bot]
2024-11-22 18:56:56 +00:00
Author: https://github.com/trflynn89
Commit: b68d67693e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2496
27 changed files with 926 additions and 3 deletions
|
@ -0,0 +1,60 @@
|
|||
describe("errors", () => {
|
||||
test("called without new", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainYearMonth();
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"Temporal.PlainYearMonth constructor must be called with 'new'"
|
||||
);
|
||||
});
|
||||
|
||||
test("cannot pass Infinity", () => {
|
||||
expect(() => {
|
||||
new Temporal.PlainYearMonth(Infinity);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain year month");
|
||||
expect(() => {
|
||||
new Temporal.PlainYearMonth(0, Infinity);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain year month");
|
||||
expect(() => {
|
||||
new Temporal.PlainYearMonth(0, 1, undefined, Infinity);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain year month");
|
||||
expect(() => {
|
||||
new Temporal.PlainYearMonth(-Infinity);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain year month");
|
||||
expect(() => {
|
||||
new Temporal.PlainYearMonth(0, -Infinity);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain year month");
|
||||
expect(() => {
|
||||
new Temporal.PlainYearMonth(0, 1, undefined, -Infinity);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain year month");
|
||||
});
|
||||
|
||||
test("cannot pass invalid ISO month/day", () => {
|
||||
expect(() => {
|
||||
new Temporal.PlainYearMonth(0, 0);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain year month");
|
||||
expect(() => {
|
||||
new Temporal.PlainYearMonth(0, 1, undefined, 0);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain year month");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("length is 2", () => {
|
||||
expect(Temporal.PlainYearMonth).toHaveLength(2);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
const plainYearMonth = new Temporal.PlainYearMonth(2021, 7);
|
||||
expect(typeof plainYearMonth).toBe("object");
|
||||
expect(plainYearMonth).toBeInstanceOf(Temporal.PlainYearMonth);
|
||||
expect(Object.getPrototypeOf(plainYearMonth)).toBe(Temporal.PlainYearMonth.prototype);
|
||||
});
|
||||
|
||||
// FIXME: Re-implement this test with Temporal.PlainYearMonth.prototype.toString({ calendarName: "always" }).
|
||||
// test("default reference day is 1", () => {
|
||||
// const plainYearMonth = new Temporal.PlainYearMonth(2021, 7);
|
||||
// const fields = plainYearMonth.getISOFields();
|
||||
// expect(fields.isoDay).toBe(1);
|
||||
// });
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue