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

LibJS: Add tests for calendar fields of DateTimeFormat's resolvedOptions

These are (mostly) testable now that LibUnicode parses format patterns.
This commit is contained in:
Timothy Flynn 2021-12-03 09:59:00 -05:00 committed by Andreas Kling
parent e42d954743
commit 20b6ffef4f

View file

@ -1,6 +1,6 @@
// NOTE: We cannot yet test the fields of ECMA-402's Table 4 (week, day, etc.) because those fields
// won't be copied into the Intl.DateTimeFormat object until the date-time pattern generator
// actually parses the CLDR patterns (see parse_date_time_pattern).
// NOTE: We cannot yet test the fractionalSecondDigits option. There aren't any patterns in the CLDR
// with this field ('S' in https://unicode.org/reports/tr35/tr35-dates.html#dfst-second). We
// will need to figure out how this field should be generated.
describe("correct behavior", () => {
test("length is 0", () => {
expect(Intl.DateTimeFormat.prototype.resolvedOptions).toHaveLength(0);
@ -115,4 +115,74 @@ describe("correct behavior", () => {
expect(el.resolvedOptions().timeStyle).toBe(style);
});
});
test("weekday", () => {
["narrow", "short", "long"].forEach(weekday => {
const en = new Intl.DateTimeFormat("en", { weekday: weekday });
expect(en.resolvedOptions().weekday).toBe(weekday);
});
});
test("era", () => {
["narrow", "short", "long"].forEach(era => {
const en = new Intl.DateTimeFormat("en", { era: era });
expect(en.resolvedOptions().era).toBe(era);
});
});
test("year", () => {
["2-digit", "numeric"].forEach(year => {
const en = new Intl.DateTimeFormat("en", { year: year });
expect(en.resolvedOptions().year).toBe(year);
});
});
test("month", () => {
["2-digit", "numeric", "narrow", "short", "long"].forEach(month => {
const en = new Intl.DateTimeFormat("en", { month: month });
expect(en.resolvedOptions().month).toBe(month);
});
});
test("day", () => {
["2-digit", "numeric"].forEach(day => {
const en = new Intl.DateTimeFormat("en", { day: day });
expect(en.resolvedOptions().day).toBe(day);
});
});
test("dayPeriod", () => {
["narrow", "short", "long"].forEach(dayPeriod => {
const en = new Intl.DateTimeFormat("en", { dayPeriod: dayPeriod });
expect(en.resolvedOptions().dayPeriod).toBe(dayPeriod);
});
});
test("hour", () => {
["2-digit", "numeric"].forEach(hour => {
const en = new Intl.DateTimeFormat("en", { hour: hour });
expect(en.resolvedOptions().hour).toBe(hour);
});
});
test("minute", () => {
["2-digit", "numeric"].forEach(minute => {
const en = new Intl.DateTimeFormat("en", { minute: minute });
expect(en.resolvedOptions().minute).toBe(minute);
});
});
test("second", () => {
["2-digit", "numeric"].forEach(second => {
const en = new Intl.DateTimeFormat("en", { second: second });
expect(en.resolvedOptions().second).toBe(second);
});
});
test("timeZoneName", () => {
["short", "long"].forEach(timeZoneName => {
const en = new Intl.DateTimeFormat("en", { timeZoneName: timeZoneName });
expect(en.resolvedOptions().timeZoneName).toBe(timeZoneName);
});
});
});