From 1583c7257c361778e8948f1743b8d916cce56bc7 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 19 Nov 2021 20:53:07 +0000 Subject: LibJS: Implement parsing of TemporalRelativeToString --- .../Instant.prototype.toZonedDateTimeISO.js | 3 +-- .../PlainDate.prototype.toZonedDateTime.js | 3 +-- .../Temporal/PlainDateTime/PlainDateTime.from.js | 3 +-- .../Temporal/PlainMonthDay/PlainMonthDay.from.js | 3 +-- .../builtins/Temporal/PlainTime/PlainTime.from.js | 3 +-- .../Temporal/PlainYearMonth/PlainYearMonth.from.js | 3 +-- .../Temporal/ZonedDateTime/ZonedDateTime.from.js | 24 +++++++++++----------- .../ZonedDateTime.prototype.withTimeZone.js | 9 +++----- 8 files changed, 21 insertions(+), 30 deletions(-) (limited to 'Userland/Libraries/LibJS/Tests') diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.prototype.toZonedDateTimeISO.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.prototype.toZonedDateTimeISO.js index 0786e0c8a3..79fee23a76 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.prototype.toZonedDateTimeISO.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.prototype.toZonedDateTimeISO.js @@ -3,8 +3,7 @@ describe("correct behavior", () => { expect(Temporal.Instant.prototype.toZonedDateTimeISO).toHaveLength(1); }); - // TODO: Un-skip when ParseTemporalTimeZoneString is fully implemented - test.skip("basic functionality", () => { + test("basic functionality", () => { const instant = new Temporal.Instant(1625614921123456789n); const zonedDateTime = instant.toZonedDateTimeISO("UTC"); expect(zonedDateTime.year).toBe(2021); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainDate/PlainDate.prototype.toZonedDateTime.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainDate/PlainDate.prototype.toZonedDateTime.js index f6c57d8908..9f3c7a8d8e 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainDate/PlainDate.prototype.toZonedDateTime.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainDate/PlainDate.prototype.toZonedDateTime.js @@ -58,8 +58,7 @@ describe("correct behavior", () => { expect(zonedDateTime.timeZone).toBe(timeZone); }); - // TODO: Enable when parse_temporal_time_zone_string() is fully implemented - test.skip("basic functionality - time zone identifier", () => { + test("basic functionality - time zone identifier", () => { // 4. in the spec const plainDate = new Temporal.PlainDate(2021, 7, 6); const zonedDateTime = plainDate.toZonedDateTime("UTC"); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainDateTime/PlainDateTime.from.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainDateTime/PlainDateTime.from.js index 433aa60fb0..5230c153a7 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainDateTime/PlainDateTime.from.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainDateTime/PlainDateTime.from.js @@ -95,8 +95,7 @@ describe("correct behavior", () => { expect(plainDateTime.nanosecond).toBe(999); }); - // Un-skip once ParseISODateTime & ParseTemporalDateString are implemented - test.skip("PlainDateTime string argument", () => { + test("PlainDateTime string argument", () => { const plainDateTime = Temporal.PlainDateTime.from("2021-07-06T23:42:01Z"); expect(plainDateTime.year).toBe(2021); expect(plainDateTime.month).toBe(7); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.from.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.from.js index 1abdc8ddb9..99f6ce55fb 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.from.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.from.js @@ -41,8 +41,7 @@ describe("correct behavior", () => { expect(plainMonthDay.day).toBe(6); }); - // Un-skip once ParseISODateTime, ToTemporalMonthDay & ParseTemporalMonthDayString are fully implemented - test.skip("from date time string", () => { + test("from date time string", () => { const plainMonthDay = Temporal.PlainMonthDay.from("2021-07-06T23:42:01Z"); expect(plainMonthDay.monthCode).toBe("M07"); expect(plainMonthDay.day).toBe(6); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainTime/PlainTime.from.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainTime/PlainTime.from.js index 5aa7e2edad..7f3069c393 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainTime/PlainTime.from.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainTime/PlainTime.from.js @@ -37,8 +37,7 @@ describe("correct behavior", () => { expect(createdPlainTime.nanosecond).toBe(0); }); - // Un-skip once ParseISODateTime & ParseTemporalTimeString are implemented - test.skip("PlainTime string argument", () => { + test("PlainTime string argument", () => { const createdPlainTime = Temporal.PlainTime.from("2021-08-27T18:44:11Z"); expect(createdPlainTime.hour).toBe(18); expect(createdPlainTime.minute).toBe(44); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainYearMonth/PlainYearMonth.from.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainYearMonth/PlainYearMonth.from.js index 0c612222d3..0ba572a08b 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainYearMonth/PlainYearMonth.from.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainYearMonth/PlainYearMonth.from.js @@ -62,8 +62,7 @@ describe("correct behavior", () => { expect(plainYearMonth.monthCode).toBe("M07"); }); - // Un-skip once ParseISODateTime & ParseTemporalYearMonthString are fully implemented - test.skip("from date time string", () => { + test("from date time string", () => { const plainYearMonth = Temporal.PlainYearMonth.from("2021-07-06T23:42:01Z"); expect(plainYearMonth.year).toBe(2021); expect(plainYearMonth.month).toBe(7); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/ZonedDateTime/ZonedDateTime.from.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/ZonedDateTime/ZonedDateTime.from.js index b662e9ce9b..313cd0cdf9 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/ZonedDateTime/ZonedDateTime.from.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/ZonedDateTime/ZonedDateTime.from.js @@ -96,7 +96,7 @@ describe("correct behavior", () => { }); // FIXME: Enable when parse_iso_date_time is implemented. - test.skip("from string", () => { + test("from string", () => { const zonedDateTime = Temporal.ZonedDateTime.from( "2021-11-07T00:20:05.100200300+00:00[UTC][u-ca=iso8601]" ); @@ -106,17 +106,17 @@ describe("correct behavior", () => { expect(zonedDateTime.timeZone.id).toBe("UTC"); expect(zonedDateTime.calendar).toBeInstanceOf(Temporal.Calendar); expect(zonedDateTime.calendar.id).toBe("iso8601"); - expect(createdZoneDateTime.year).toBe(2021); - expect(createdZoneDateTime.month).toBe(11); - expect(createdZoneDateTime.day).toBe(7); - expect(createdZoneDateTime.hour).toBe(0); - expect(createdZoneDateTime.minute).toBe(20); - expect(createdZoneDateTime.second).toBe(5); - expect(createdZoneDateTime.millisecond).toBe(100); - expect(createdZoneDateTime.microsecond).toBe(200); - expect(createdZoneDateTime.nanosecond).toBe(300); - expect(createdZoneDateTime.offset).toBe("+00:00"); - expect(createdZoneDateTime.offsetNanoseconds).toBe(0); + expect(zonedDateTime.year).toBe(2021); + expect(zonedDateTime.month).toBe(11); + expect(zonedDateTime.day).toBe(7); + expect(zonedDateTime.hour).toBe(0); + expect(zonedDateTime.minute).toBe(20); + expect(zonedDateTime.second).toBe(5); + expect(zonedDateTime.millisecond).toBe(100); + expect(zonedDateTime.microsecond).toBe(200); + expect(zonedDateTime.nanosecond).toBe(300); + expect(zonedDateTime.offset).toBe("+00:00"); + expect(zonedDateTime.offsetNanoseconds).toBe(0); }); }); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/ZonedDateTime/ZonedDateTime.prototype.withTimeZone.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/ZonedDateTime/ZonedDateTime.prototype.withTimeZone.js index 9d5276ccbd..7a391bcced 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/ZonedDateTime/ZonedDateTime.prototype.withTimeZone.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/ZonedDateTime/ZonedDateTime.prototype.withTimeZone.js @@ -13,8 +13,7 @@ describe("correct behavior", () => { expect(withTimeZoneZonedDateTime.timeZone).toBe(timeZone); }); - // FIXME: Enable this when time zone string parsing is implemented. - test.skip("from time zone string", () => { + test("from time zone string", () => { const object = {}; const zonedDateTime = new Temporal.ZonedDateTime(1n, object); expect(zonedDateTime.timeZone).toBe(object); @@ -32,13 +31,11 @@ describe("errors", () => { }).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime"); }); - // FIXME: Enable this when time zone string parsing is implemented. - test.skip("from invalid time zone string", () => { + test("from invalid time zone string", () => { const zonedDateTime = new Temporal.ZonedDateTime(1n, {}); - // FIXME: Use "toThrowWithMessage" once this has an error message. expect(() => { zonedDateTime.withTimeZone("UTCfoobar"); - }).toThrow(RangeError); + }).toThrowWithMessage(RangeError, "Invalid time zone string 'UTCfoobar'"); }); }); -- cgit v1.2.3