mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:37:36 +00:00
LibJS: Implement Temporal.PlainYearMonth.prototype.toString()
This commit is contained in:
parent
89eddb5bff
commit
421ad73b4f
5 changed files with 116 additions and 0 deletions
|
@ -0,0 +1,51 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 0", () => {
|
||||
expect(Temporal.PlainYearMonth.prototype.toString).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
let plainYearMonth;
|
||||
|
||||
plainYearMonth = new Temporal.PlainYearMonth(2021, 7);
|
||||
expect(plainYearMonth.toString()).toBe("2021-07");
|
||||
expect(plainYearMonth.toString({ calendarName: "auto" })).toBe("2021-07");
|
||||
expect(plainYearMonth.toString({ calendarName: "always" })).toBe("2021-07[u-ca=iso8601]");
|
||||
expect(plainYearMonth.toString({ calendarName: "never" })).toBe("2021-07");
|
||||
|
||||
plainYearMonth = new Temporal.PlainYearMonth(2021, 7, { toString: () => "foo" }, 6);
|
||||
expect(plainYearMonth.toString()).toBe("2021-07-06[u-ca=foo]");
|
||||
expect(plainYearMonth.toString({ calendarName: "auto" })).toBe("2021-07-06[u-ca=foo]");
|
||||
expect(plainYearMonth.toString({ calendarName: "always" })).toBe("2021-07-06[u-ca=foo]");
|
||||
expect(plainYearMonth.toString({ calendarName: "never" })).toBe("2021-07-06");
|
||||
|
||||
plainYearMonth = new Temporal.PlainYearMonth(0, 1);
|
||||
expect(plainYearMonth.toString()).toBe("+000000-01");
|
||||
|
||||
plainYearMonth = new Temporal.PlainYearMonth(999, 1);
|
||||
expect(plainYearMonth.toString()).toBe("+000999-01");
|
||||
|
||||
plainYearMonth = new Temporal.PlainYearMonth(12345, 1);
|
||||
expect(plainYearMonth.toString()).toBe("+012345-01");
|
||||
|
||||
plainYearMonth = new Temporal.PlainYearMonth(123456, 1);
|
||||
expect(plainYearMonth.toString()).toBe("+123456-01");
|
||||
|
||||
plainYearMonth = new Temporal.PlainYearMonth(-12345, 1);
|
||||
expect(plainYearMonth.toString()).toBe("-012345-01");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainYearMonth object", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainYearMonth.prototype.toString.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Temporal.PlainYearMonth");
|
||||
});
|
||||
|
||||
test("calendarName option must be one of 'auto', 'always', 'never'", () => {
|
||||
const plainYearMonth = new Temporal.PlainYearMonth(2021, 7);
|
||||
expect(() => {
|
||||
plainYearMonth.toString({ calendarName: "foo" });
|
||||
}).toThrowWithMessage(RangeError, "foo is not a valid value for option calendarName");
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue