mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-30 22:28:22 +00:00
LibJS: Implement stringification Temporal.PlainYearMonth prototypes
This commit is contained in:
parent
b68d67693e
commit
2da526423f
Notes:
github-actions[bot]
2024-11-22 18:56:48 +00:00
Author: https://github.com/trflynn89
Commit: 2da526423f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2496
8 changed files with 193 additions and 6 deletions
|
@ -51,10 +51,10 @@ describe("normal behavior", () => {
|
|||
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);
|
||||
// });
|
||||
test("default reference day is 1", () => {
|
||||
const plainYearMonth = new Temporal.PlainYearMonth(2021, 7);
|
||||
const fields = plainYearMonth.toString({ calendarName: "always" });
|
||||
const day = fields.split("-")[2].split("[")[0];
|
||||
expect(day).toBe("01");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 0", () => {
|
||||
expect(Temporal.PlainYearMonth.prototype.toJSON).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
let plainYearMonth;
|
||||
|
||||
plainYearMonth = new Temporal.PlainYearMonth(2021, 7);
|
||||
expect(plainYearMonth.toJSON()).toBe("2021-07");
|
||||
|
||||
plainYearMonth = new Temporal.PlainYearMonth(2021, 7, "gregory", 6);
|
||||
expect(plainYearMonth.toJSON()).toBe("2021-07-06[u-ca=gregory]");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainYearMonth object", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainYearMonth.prototype.toJSON.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainYearMonth");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 0", () => {
|
||||
expect(Temporal.PlainYearMonth.prototype.toLocaleString).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
let plainYearMonth;
|
||||
|
||||
plainYearMonth = new Temporal.PlainYearMonth(2021, 7);
|
||||
expect(plainYearMonth.toLocaleString()).toBe("2021-07");
|
||||
|
||||
plainYearMonth = new Temporal.PlainYearMonth(2021, 7, "gregory", 6);
|
||||
expect(plainYearMonth.toLocaleString()).toBe("2021-07-06[u-ca=gregory]");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainYearMonth object", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainYearMonth.prototype.toLocaleString.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainYearMonth");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,64 @@
|
|||
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-01[u-ca=iso8601]"
|
||||
);
|
||||
expect(plainYearMonth.toString({ calendarName: "never" })).toBe("2021-07");
|
||||
expect(plainYearMonth.toString({ calendarName: "critical" })).toBe(
|
||||
"2021-07-01[!u-ca=iso8601]"
|
||||
);
|
||||
|
||||
plainYearMonth = new Temporal.PlainYearMonth(2021, 7, "gregory", 6);
|
||||
expect(plainYearMonth.toString()).toBe("2021-07-06[u-ca=gregory]");
|
||||
expect(plainYearMonth.toString({ calendarName: "auto" })).toBe("2021-07-06[u-ca=gregory]");
|
||||
expect(plainYearMonth.toString({ calendarName: "always" })).toBe(
|
||||
"2021-07-06[u-ca=gregory]"
|
||||
);
|
||||
expect(plainYearMonth.toString({ calendarName: "never" })).toBe("2021-07-06");
|
||||
expect(plainYearMonth.toString({ calendarName: "critical" })).toBe(
|
||||
"2021-07-06[!u-ca=gregory]"
|
||||
);
|
||||
|
||||
plainYearMonth = new Temporal.PlainYearMonth(0, 1);
|
||||
expect(plainYearMonth.toString()).toBe("0000-01");
|
||||
|
||||
plainYearMonth = new Temporal.PlainYearMonth(999, 1);
|
||||
expect(plainYearMonth.toString()).toBe("0999-01");
|
||||
|
||||
plainYearMonth = new Temporal.PlainYearMonth(9999, 1);
|
||||
expect(plainYearMonth.toString()).toBe("9999-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 an object of type Temporal.PlainYearMonth");
|
||||
});
|
||||
|
||||
test("calendarName option must be one of 'auto', 'always', 'never', 'critical'", () => {
|
||||
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