From 63933d1da5946cc39763981ff63b704795feaf58 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Tue, 26 Mar 2024 11:26:14 -0700 Subject: [PATCH] Temporal: Tests that dateStyle affects toLocaleString output For each Temporal type, add a test (which should not be sensitive to the exact locale format) that ensures dateStyle affects the output, for a Gregorian and non-Gregorian calendar. See https://github.com/tc39/proposal-temporal/issues/2058 --- .../prototype/toLocaleString/dateStyle.js | 28 +++++++++++++++++ .../prototype/toLocaleString/dateStyle.js | 31 +++++++++++++++++++ .../prototype/toLocaleString/dateStyle.js | 31 +++++++++++++++++++ .../prototype/toLocaleString/dateStyle.js | 31 +++++++++++++++++++ .../prototype/toLocaleString/dateStyle.js | 31 +++++++++++++++++++ .../prototype/toLocaleString/dateStyle.js | 31 +++++++++++++++++++ 6 files changed, 183 insertions(+) create mode 100644 test/intl402/Temporal/Instant/prototype/toLocaleString/dateStyle.js create mode 100644 test/intl402/Temporal/PlainDate/prototype/toLocaleString/dateStyle.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/toLocaleString/dateStyle.js create mode 100644 test/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/dateStyle.js create mode 100644 test/intl402/Temporal/PlainYearMonth/prototype/toLocaleString/dateStyle.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/dateStyle.js diff --git a/test/intl402/Temporal/Instant/prototype/toLocaleString/dateStyle.js b/test/intl402/Temporal/Instant/prototype/toLocaleString/dateStyle.js new file mode 100644 index 0000000000..fc2ca84f3d --- /dev/null +++ b/test/intl402/Temporal/Instant/prototype/toLocaleString/dateStyle.js @@ -0,0 +1,28 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.tolocalestring +description: Basic tests that dateStyle option affects output +locale: [en-u-ca-gregory, en-u-ca-islamic] +features: [Temporal, Intl.DateTimeFormat-datetimestyle] +---*/ + +const instant = new Temporal.Instant(1711475200_000_000_000n); + +assert( + instant.toLocaleString("en-u-ca-gregory", { dateStyle: "long" }).includes("March"), + "dateStyle: long writes month of March out in full" +); +assert( + !instant.toLocaleString("en-u-ca-gregory", { dateStyle: "short" }).includes("March"), + "dateStyle: short does not write month of March out in full" +); +assert( + instant.toLocaleString("en-u-ca-islamic", { dateStyle: "long" }).includes("Ramadan"), + "dateStyle: long writes month of Ramadan out in full" +); +assert( + !instant.toLocaleString("en-u-ca-islamic", { dateStyle: "short" }).includes("Ramadan"), + "dateStyle: short does not write month of Ramadan out in full" +); diff --git a/test/intl402/Temporal/PlainDate/prototype/toLocaleString/dateStyle.js b/test/intl402/Temporal/PlainDate/prototype/toLocaleString/dateStyle.js new file mode 100644 index 0000000000..68db35e0b2 --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/toLocaleString/dateStyle.js @@ -0,0 +1,31 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tolocalestring +description: Basic tests that dateStyle option affects output +locale: [en-u-ca-gregory, en-u-ca-islamic] +features: [Temporal, Intl.DateTimeFormat-datetimestyle] +---*/ + +const dateGregorian = new Temporal.PlainDate(2024, 3, 26, "gregory"); + +assert( + dateGregorian.toLocaleString("en-u-ca-gregory", { dateStyle: "long" }).includes("March"), + "dateStyle: long writes month of March out in full" +); +assert( + !dateGregorian.toLocaleString("en-u-ca-gregory", { dateStyle: "short" }).includes("March"), + "dateStyle: short does not write month of March out in full" +); + +const dateIslamic = new Temporal.PlainDate(2024, 3, 26, "islamic"); + +assert( + dateIslamic.toLocaleString("en-u-ca-islamic", { dateStyle: "long" }).includes("Ramadan"), + "dateStyle: long writes month of Ramadan out in full" +); +assert( + !dateIslamic.toLocaleString("en-u-ca-islamic", { dateStyle: "short" }).includes("Ramadan"), + "dateStyle: short does not write month of Ramadan out in full" +); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/toLocaleString/dateStyle.js b/test/intl402/Temporal/PlainDateTime/prototype/toLocaleString/dateStyle.js new file mode 100644 index 0000000000..39f07d6dad --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/toLocaleString/dateStyle.js @@ -0,0 +1,31 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.tolocalestring +description: Basic tests that dateStyle option affects output +locale: [en-u-ca-gregory, en-u-ca-islamic] +features: [Temporal, Intl.DateTimeFormat-datetimestyle] +---*/ + +const dateGregorian = new Temporal.PlainDateTime(2024, 3, 26, 10, 30, 0, 0, 0, 0, "gregory"); + +assert( + dateGregorian.toLocaleString("en-u-ca-gregory", { dateStyle: "long" }).includes("March"), + "dateStyle: long writes month of March out in full" +); +assert( + !dateGregorian.toLocaleString("en-u-ca-gregory", { dateStyle: "short" }).includes("March"), + "dateStyle: short does not write month of March out in full" +); + +const dateIslamic = new Temporal.PlainDateTime(2024, 3, 26, 10, 30, 0, 0, 0, 0, "islamic"); + +assert( + dateIslamic.toLocaleString("en-u-ca-islamic", { dateStyle: "long" }).includes("Ramadan"), + "dateStyle: long writes month of Ramadan out in full" +); +assert( + !dateIslamic.toLocaleString("en-u-ca-islamic", { dateStyle: "short" }).includes("Ramadan"), + "dateStyle: short does not write month of Ramadan out in full" +); diff --git a/test/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/dateStyle.js b/test/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/dateStyle.js new file mode 100644 index 0000000000..55c855ae54 --- /dev/null +++ b/test/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/dateStyle.js @@ -0,0 +1,31 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.prototype.tolocalestring +description: Basic tests that dateStyle option affects output +locale: [en-u-ca-gregory, en-u-ca-islamic] +features: [Temporal, Intl.DateTimeFormat-datetimestyle] +---*/ + +const dateGregorian = Temporal.PlainMonthDay.from({ monthCode: "M03", day: 26, calendar: "gregory" }); + +assert( + dateGregorian.toLocaleString("en-u-ca-gregory", { dateStyle: "long" }).includes("March"), + "dateStyle: long writes month of March out in full" +); +assert( + !dateGregorian.toLocaleString("en-u-ca-gregory", { dateStyle: "short" }).includes("March"), + "dateStyle: short does not write month of March out in full" +); + +const dateIslamic = Temporal.PlainMonthDay.from({ monthCode: "M09", day: 16, calendar: "islamic" }); + +assert( + dateIslamic.toLocaleString("en-u-ca-islamic", { dateStyle: "long" }).includes("Ramadan"), + "dateStyle: long writes month of Ramadan out in full" +); +assert( + !dateIslamic.toLocaleString("en-u-ca-islamic", { dateStyle: "short" }).includes("Ramadan"), + "dateStyle: short does not write month of Ramadan out in full" +); diff --git a/test/intl402/Temporal/PlainYearMonth/prototype/toLocaleString/dateStyle.js b/test/intl402/Temporal/PlainYearMonth/prototype/toLocaleString/dateStyle.js new file mode 100644 index 0000000000..0fbb25adea --- /dev/null +++ b/test/intl402/Temporal/PlainYearMonth/prototype/toLocaleString/dateStyle.js @@ -0,0 +1,31 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.tolocalestring +description: Basic tests that dateStyle option affects output +locale: [en-u-ca-gregory, en-u-ca-islamic] +features: [Temporal, Intl.DateTimeFormat-datetimestyle] +---*/ + +const dateGregorian = Temporal.PlainYearMonth.from({ year: 2024, monthCode: "M03", calendar: "gregory" }); + +assert( + dateGregorian.toLocaleString("en-u-ca-gregory", { dateStyle: "long" }).includes("March"), + "dateStyle: long writes month of March out in full" +); +assert( + !dateGregorian.toLocaleString("en-u-ca-gregory", { dateStyle: "short" }).includes("March"), + "dateStyle: short does not write month of March out in full" +); + +const dateIslamic = Temporal.PlainYearMonth.from({ year: 1445, monthCode: "M09", calendar: "islamic" }); + +assert( + dateIslamic.toLocaleString("en-u-ca-islamic", { dateStyle: "long" }).includes("Ramadan"), + "dateStyle: long writes month of Ramadan out in full" +); +assert( + !dateIslamic.toLocaleString("en-u-ca-islamic", { dateStyle: "short" }).includes("Ramadan"), + "dateStyle: short does not write month of Ramadan out in full" +); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/dateStyle.js b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/dateStyle.js new file mode 100644 index 0000000000..a27d5e9e94 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/dateStyle.js @@ -0,0 +1,31 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tolocalestring +description: Basic tests that dateStyle option affects output +locale: [en-u-ca-gregory, en-u-ca-islamic] +features: [Temporal, Intl.DateTimeFormat-datetimestyle] +---*/ + +const dateGregorian = new Temporal.ZonedDateTime(1711475200_000_000_000n, "UTC", "gregory"); + +assert( + dateGregorian.toLocaleString("en-u-ca-gregory", { dateStyle: "long" }).includes("March"), + "dateStyle: long writes month of March out in full" +); +assert( + !dateGregorian.toLocaleString("en-u-ca-gregory", { dateStyle: "short" }).includes("March"), + "dateStyle: short does not write month of March out in full" +); + +const dateIslamic = new Temporal.ZonedDateTime(1711475200_000_000_000n, "UTC", "islamic"); + +assert( + dateIslamic.toLocaleString("en-u-ca-islamic", { dateStyle: "long" }).includes("Ramadan"), + "dateStyle: long writes month of Ramadan out in full" +); +assert( + !dateIslamic.toLocaleString("en-u-ca-islamic", { dateStyle: "short" }).includes("Ramadan"), + "dateStyle: short does not write month of Ramadan out in full" +);