mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:27:45 +00:00
LibJS: Start implementing Temporal.PlainYearMonth
This commit adds the PlainYearMonth object itself, its constructor and prototype (currently empty), and the CreateTemporalYearMonth and ISOYearMonthWithinLimits abstract operations.
This commit is contained in:
parent
5b12542d39
commit
0a8edd5ce7
12 changed files with 360 additions and 10 deletions
|
@ -0,0 +1,53 @@
|
|||
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, 0, {}, 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, 0, {}, -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, {}, 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);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue