1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 06:37:35 +00:00

LibJS: Add calendarName: "critical" option to toString() methods

This is a normative change in the Temporal spec.

See: e715a50
This commit is contained in:
Luke Wilde 2022-11-02 19:24:47 +00:00 committed by Linus Groh
parent 192aa75279
commit 4a167cfbec
9 changed files with 73 additions and 15 deletions

View file

@ -80,6 +80,21 @@ describe("correct behavior", () => {
expect(plainDateTime.toString(options)).toBe("2022-08-08T14:38:40.1002003");
expect(calledToString).toBeFalse();
});
test("calendarName option", () => {
const plainDateTime = new Temporal.PlainDateTime(2022, 11, 2, 19, 4, 35, 100, 200, 300);
const values = [
["auto", "2022-11-02T19:04:35.1002003"],
["always", "2022-11-02T19:04:35.1002003[u-ca=iso8601]"],
["never", "2022-11-02T19:04:35.1002003"],
["critical", "2022-11-02T19:04:35.1002003[!u-ca=iso8601]"],
];
for (const [calendarName, expected] of values) {
const options = { calendarName };
expect(plainDateTime.toString(options)).toBe(expected);
}
});
});
describe("errors", () => {
@ -88,4 +103,11 @@ describe("errors", () => {
Temporal.PlainDateTime.prototype.toString.call("foo");
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDateTime");
});
test("calendarName option must be one of 'auto', 'always', 'never', 'critical'", () => {
const plainDateTime = new Temporal.PlainDateTime(2022, 11, 2, 19, 5, 40, 100, 200, 300);
expect(() => {
plainDateTime.toString({ calendarName: "foo" });
}).toThrowWithMessage(RangeError, "foo is not a valid value for option calendarName");
});
});