mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:07:35 +00:00
LibJS: Implement Temporal.PlainDate.prototype.toString()
This commit is contained in:
parent
310192f918
commit
402f04c2fc
10 changed files with 164 additions and 0 deletions
|
@ -0,0 +1,51 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 0", () => {
|
||||
expect(Temporal.PlainDate.prototype.toString).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
let plainDate;
|
||||
|
||||
plainDate = new Temporal.PlainDate(2021, 7, 6);
|
||||
expect(plainDate.toString()).toBe("2021-07-06");
|
||||
expect(plainDate.toString({ calendarName: "auto" })).toBe("2021-07-06");
|
||||
expect(plainDate.toString({ calendarName: "always" })).toBe("2021-07-06[u-ca=iso8601]");
|
||||
expect(plainDate.toString({ calendarName: "never" })).toBe("2021-07-06");
|
||||
|
||||
plainDate = new Temporal.PlainDate(2021, 7, 6, { toString: () => "foo" });
|
||||
expect(plainDate.toString()).toBe("2021-07-06[u-ca=foo]");
|
||||
expect(plainDate.toString({ calendarName: "auto" })).toBe("2021-07-06[u-ca=foo]");
|
||||
expect(plainDate.toString({ calendarName: "always" })).toBe("2021-07-06[u-ca=foo]");
|
||||
expect(plainDate.toString({ calendarName: "never" })).toBe("2021-07-06");
|
||||
|
||||
plainDate = new Temporal.PlainDate(0, 1, 1);
|
||||
expect(plainDate.toString()).toBe("+000000-01-01");
|
||||
|
||||
plainDate = new Temporal.PlainDate(999, 1, 1);
|
||||
expect(plainDate.toString()).toBe("+000999-01-01");
|
||||
|
||||
plainDate = new Temporal.PlainDate(12345, 1, 1);
|
||||
expect(plainDate.toString()).toBe("+012345-01-01");
|
||||
|
||||
plainDate = new Temporal.PlainDate(123456, 1, 1);
|
||||
expect(plainDate.toString()).toBe("+123456-01-01");
|
||||
|
||||
plainDate = new Temporal.PlainDate(-12345, 1, 1);
|
||||
expect(plainDate.toString()).toBe("-012345-01-01");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainDate object", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainDate.prototype.toString.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Temporal.PlainDate");
|
||||
});
|
||||
|
||||
test("calendarName option must be one of 'auto', 'always', 'never'", () => {
|
||||
const plainDate = new Temporal.PlainDate(2021, 7, 6);
|
||||
expect(() => {
|
||||
plainDate.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