summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/DateTimeFormat/calendar-option.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/Intl/DateTimeFormat/calendar-option.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Intl/DateTimeFormat/calendar-option.js')
-rw-r--r--js/src/tests/non262/Intl/DateTimeFormat/calendar-option.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/DateTimeFormat/calendar-option.js b/js/src/tests/non262/Intl/DateTimeFormat/calendar-option.js
new file mode 100644
index 0000000000..cbf73df5c9
--- /dev/null
+++ b/js/src/tests/non262/Intl/DateTimeFormat/calendar-option.js
@@ -0,0 +1,67 @@
+const defaultLocale = "en";
+const defaultCalendar = new Intl.DateTimeFormat(defaultLocale).resolvedOptions().calendar;
+
+function createWithLocale(locale, calendar) {
+ return new Intl.DateTimeFormat(locale, {calendar});
+}
+
+function create(calendar) {
+ return createWithLocale(defaultLocale, calendar);
+}
+
+// Empty string should throw.
+assertThrowsInstanceOf(() => create(""), RangeError);
+
+// Trailing \0 should throw.
+assertThrowsInstanceOf(() => create("gregory\0"), RangeError);
+
+// Too short or too long strings should throw.
+assertThrowsInstanceOf(() => create("a"), RangeError);
+assertThrowsInstanceOf(() => create("toolongstring"), RangeError);
+
+// Throw even when prefix is valid.
+assertThrowsInstanceOf(() => create("gregory-toolongstring"), RangeError);
+
+// |calendar| can be set to |undefined|.
+let dtf = create(undefined);
+assertEq(dtf.resolvedOptions().calendar, defaultCalendar);
+
+// Unsupported calendars are ignored.
+dtf = create("xxxxxxxx");
+assertEq(dtf.resolvedOptions().calendar, defaultCalendar);
+
+// Calendars in options overwrite Unicode extension keyword.
+dtf = createWithLocale(`${defaultLocale}-u-ca-iso8601`, "japanese");
+assertEq(dtf.resolvedOptions().locale, defaultLocale);
+assertEq(dtf.resolvedOptions().calendar, "japanese");
+
+// |calendar| option ignores case.
+dtf = create("CHINESE");
+assertEq(dtf.resolvedOptions().locale, defaultLocale);
+assertEq(dtf.resolvedOptions().calendar, "chinese");
+
+const calendars = [
+ "buddhist", "chinese", "coptic", "dangi", "ethioaa", "ethiopic-amete-alem",
+ "ethiopic", "gregory", "hebrew", "indian", "islamic", "islamic-umalqura",
+ "islamic-tbla", "islamic-civil", "islamic-rgsa", "iso8601", "japanese",
+ "persian", "roc", "islamicc",
+];
+
+// https://github.com/tc39/proposal-intl-locale/issues/96
+const canonical = {
+ "islamicc": "islamic-civil",
+ "ethiopic-amete-alem": "ethioaa",
+};
+
+for (let calendar of calendars) {
+ let dtf1 = new Intl.DateTimeFormat(`${defaultLocale}-u-ca-${calendar}`);
+ let dtf2 = new Intl.DateTimeFormat(defaultLocale, {calendar});
+
+ assertEq(dtf1.resolvedOptions().calendar, canonical[calendar] ?? calendar);
+ assertEq(dtf2.resolvedOptions().calendar, canonical[calendar] ?? calendar);
+
+ assertEq(dtf2.format(0), dtf1.format(0));
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);