mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-13 03:29:49 +00:00
LibJS: Implement stringification Temporal.PlainMonthDay prototypes
This commit is contained in:
parent
1a386e78c3
commit
5bccb36a6f
Notes:
github-actions[bot]
2024-11-22 00:25:37 +00:00
Author: https://github.com/trflynn89
Commit: 5bccb36a6f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2471
14 changed files with 238 additions and 7 deletions
|
@ -57,10 +57,10 @@ describe("normal behavior", () => {
|
|||
expect(Object.getPrototypeOf(plainMonthDay)).toBe(Temporal.PlainMonthDay.prototype);
|
||||
});
|
||||
|
||||
// FIXME: Re-implement this test with Temporal.PlainMonthDay.prototype.toString({ calendarName: "always" }).
|
||||
// test("default reference year is 1972", () => {
|
||||
// const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
|
||||
// const fields = plainMonthDay.getISOFields();
|
||||
// expect(fields.isoYear).toBe(1972);
|
||||
// });
|
||||
test("default reference year is 1972", () => {
|
||||
const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
|
||||
const fields = plainMonthDay.toString({ calendarName: "always" });
|
||||
const year = fields.split("-")[0];
|
||||
expect(year).toBe("1972");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 0", () => {
|
||||
expect(Temporal.PlainMonthDay.prototype.toJSON).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
let plainMonthDay;
|
||||
|
||||
plainMonthDay = new Temporal.PlainMonthDay(7, 6);
|
||||
expect(plainMonthDay.toJSON()).toBe("07-06");
|
||||
|
||||
plainMonthDay = new Temporal.PlainMonthDay(7, 6, "gregory", 2021);
|
||||
expect(plainMonthDay.toJSON()).toBe("2021-07-06[u-ca=gregory]");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainMonthDay object", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainMonthDay.prototype.toJSON.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainMonthDay");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 0", () => {
|
||||
expect(Temporal.PlainMonthDay.prototype.toLocaleString).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
let plainMonthDay;
|
||||
|
||||
plainMonthDay = new Temporal.PlainMonthDay(7, 6);
|
||||
expect(plainMonthDay.toLocaleString()).toBe("07-06");
|
||||
|
||||
plainMonthDay = new Temporal.PlainMonthDay(7, 6, "gregory", 2021);
|
||||
expect(plainMonthDay.toLocaleString()).toBe("2021-07-06[u-ca=gregory]");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainMonthDay object", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainMonthDay.prototype.toLocaleString.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainMonthDay");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,42 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 0", () => {
|
||||
expect(Temporal.PlainMonthDay.prototype.toString).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
let plainMonthDay;
|
||||
|
||||
plainMonthDay = new Temporal.PlainMonthDay(7, 6);
|
||||
expect(plainMonthDay.toString()).toBe("07-06");
|
||||
expect(plainMonthDay.toString({ calendarName: "auto" })).toBe("07-06");
|
||||
expect(plainMonthDay.toString({ calendarName: "always" })).toBe("1972-07-06[u-ca=iso8601]");
|
||||
expect(plainMonthDay.toString({ calendarName: "never" })).toBe("07-06");
|
||||
expect(plainMonthDay.toString({ calendarName: "critical" })).toBe(
|
||||
"1972-07-06[!u-ca=iso8601]"
|
||||
);
|
||||
|
||||
plainMonthDay = new Temporal.PlainMonthDay(7, 6, "gregory", 2021);
|
||||
expect(plainMonthDay.toString()).toBe("2021-07-06[u-ca=gregory]");
|
||||
expect(plainMonthDay.toString({ calendarName: "auto" })).toBe("2021-07-06[u-ca=gregory]");
|
||||
expect(plainMonthDay.toString({ calendarName: "always" })).toBe("2021-07-06[u-ca=gregory]");
|
||||
expect(plainMonthDay.toString({ calendarName: "never" })).toBe("2021-07-06");
|
||||
expect(plainMonthDay.toString({ calendarName: "critical" })).toBe(
|
||||
"2021-07-06[!u-ca=gregory]"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainMonthDay object", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainMonthDay.prototype.toString.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainMonthDay");
|
||||
});
|
||||
|
||||
test("calendarName option must be one of 'auto', 'always', 'never', 'critical'", () => {
|
||||
const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
|
||||
expect(() => {
|
||||
plainMonthDay.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