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
This commit is contained in:
Philip Chimento 2024-03-26 11:26:14 -07:00 committed by Ms2ger
parent a074d97c5b
commit 63933d1da5
6 changed files with 183 additions and 0 deletions

View File

@ -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"
);

View File

@ -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"
);

View File

@ -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"
);

View File

@ -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"
);

View File

@ -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"
);

View File

@ -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"
);