1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:47:45 +00:00

LibJS: Implement parsing of TemporalYearMonthString

This commit is contained in:
Linus Groh 2021-11-19 19:19:29 +00:00
parent 3ddab2f4fe
commit 3b1de431cc
5 changed files with 56 additions and 6 deletions

View file

@ -55,8 +55,15 @@ describe("correct behavior", () => {
expect(plainYearMonth.inLeapYear).toBeFalse();
});
test("from year month string", () => {
const plainYearMonth = Temporal.PlainYearMonth.from("2021-07");
expect(plainYearMonth.year).toBe(2021);
expect(plainYearMonth.month).toBe(7);
expect(plainYearMonth.monthCode).toBe("M07");
});
// Un-skip once ParseISODateTime & ParseTemporalYearMonthString are fully implemented
test.skip("PlainYearMonth string argument", () => {
test.skip("from date time string", () => {
const plainYearMonth = Temporal.PlainYearMonth.from("2021-07-06T23:42:01Z");
expect(plainYearMonth.year).toBe(2021);
expect(plainYearMonth.month).toBe(7);
@ -80,4 +87,10 @@ describe("errors", () => {
Temporal.PlainYearMonth.from({ month: 1 });
}).toThrowWithMessage(TypeError, "Required property year is missing or undefined");
});
test("invalid year month string", () => {
expect(() => {
Temporal.PlainYearMonth.from("foo");
}).toThrowWithMessage(RangeError, "Invalid year month string 'foo'");
});
});