summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/DisplayNames
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/non262/Intl/DisplayNames')
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/abbreviated.js28
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/alias-and-parent-locales.js33
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/browser.js0
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/calendar.js123
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/currency.js150
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/dateTimeField.js176
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/dayPeriod.js80
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/language-dialect.js104
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/language.js205
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/month-calendar.js18
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/month.js104
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/quarter.js74
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/region.js157
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/script.js134
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/shell.js6
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/weekday.js77
16 files changed, 1469 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/DisplayNames/abbreviated.js b/js/src/tests/non262/Intl/DisplayNames/abbreviated.js
new file mode 100644
index 0000000000..4203ffcbac
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/abbreviated.js
@@ -0,0 +1,28 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl')||!this.hasOwnProperty('addIntlExtras'))
+
+addMozIntlDisplayNames(this);
+
+const tests = {
+ "en": {
+ long: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
+ abbreviated: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
+ short: ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
+ narrow: ["M", "T", "W", "T", "F", "S", "S"],
+ },
+};
+
+for (let [locale, localeTests] of Object.entries(tests)) {
+ for (let [style, weekdays] of Object.entries(localeTests)) {
+ let dn = new Intl.DisplayNames(locale, {type: "weekday", style});
+
+ let resolved = dn.resolvedOptions();
+ assertEq(resolved.style, style);
+
+ for (let [day, expected] of weekdays.entries()) {
+ assertEq(dn.of(day + 1), expected);
+ }
+ }
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Intl/DisplayNames/alias-and-parent-locales.js b/js/src/tests/non262/Intl/DisplayNames/alias-and-parent-locales.js
new file mode 100644
index 0000000000..d60a1593d4
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/alias-and-parent-locales.js
@@ -0,0 +1,33 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl'))
+
+// Ensure alias and parent locales are correctly picked up when calling into ICU.
+
+// "zh-HK" is an alias to "zh-Hant-HK", so display names should default to
+// traditional instead of simplified characters.
+{
+ const zh_Hant = new Intl.DisplayNames("zh-Hant", {type: "region"});
+ const zh_Hans = new Intl.DisplayNames("zh-Hans", {type: "region"});
+ const zh_HK = new Intl.DisplayNames("zh-HK", {type: "region"});
+
+ // We assume traditional and simplified have different outputs.
+ assertEq(zh_Hant.of("US") === zh_Hans.of("US"), false);
+
+ // "zh-HK" should use traditional characters.
+ assertEq(zh_HK.of("US"), zh_Hant.of("US"));
+}
+
+// The parent locale of "en-AU" is "en-001" and not "en" (because "en" actually means "en-US").
+{
+ const en = new Intl.DisplayNames("en", {type: "language"});
+ const en_001 = new Intl.DisplayNames("en-001", {type: "language"});
+ const en_AU = new Intl.DisplayNames("en-AU", {type: "language"});
+
+ // We assume "en" and "en-001" have different outputs.
+ assertEq(en.of("nds-NL") === en_001.of("nds-NL"), false);
+
+ // "en-AU" should have the same output as "en-001".
+ assertEq(en_AU.of("nds-NL"), en_001.of("nds-NL"));
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Intl/DisplayNames/browser.js b/js/src/tests/non262/Intl/DisplayNames/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/browser.js
diff --git a/js/src/tests/non262/Intl/DisplayNames/calendar.js b/js/src/tests/non262/Intl/DisplayNames/calendar.js
new file mode 100644
index 0000000000..0700ee2888
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/calendar.js
@@ -0,0 +1,123 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl'))
+
+const tests = {
+ "en": {
+ long: {
+ "gregory": "Gregorian Calendar",
+ "iso8601": "ISO-8601 Calendar",
+ "japanese": "Japanese Calendar",
+ "islamic-civil": "Islamic Calendar (tabular, civil epoch)",
+ "islamicc": "Islamic Calendar (tabular, civil epoch)",
+ "ethioaa": "Ethiopic Amete Alem Calendar",
+ "ethiopic-amete-alem": "Ethiopic Amete Alem Calendar",
+ },
+ short: {},
+ narrow: {},
+ },
+ "de": {
+ long: {
+ "gregory": "Gregorianischer Kalender",
+ "iso8601": "ISO-8601-Kalender",
+ "japanese": "Japanischer Kalender",
+ "islamic-civil": "Bürgerlicher islamischer Kalender (tabellarisch)",
+ "islamicc": "Bürgerlicher islamischer Kalender (tabellarisch)",
+ "ethioaa": "Äthiopischer Amätä-Aläm-Kalender",
+ "ethiopic-amete-alem": "Äthiopischer Amätä-Aläm-Kalender",
+ },
+ short: {},
+ narrow: {},
+ },
+ "fr": {
+ long: {
+ "gregory": "calendrier grégorien",
+ "iso8601": "calendrier ISO 8601",
+ "japanese": "calendrier japonais",
+ "islamic-civil": "calendrier musulman (tabulaire, époque civile)",
+ "islamicc": "calendrier musulman (tabulaire, époque civile)",
+ "ethioaa": "calendrier éthiopien Amete Alem",
+ "ethiopic-amete-alem": "calendrier éthiopien Amete Alem",
+ },
+ short: {},
+ narrow: {},
+ },
+ "zh": {
+ long: {
+ "gregory": "公历",
+ "iso8601": "国际标准历法",
+ "japanese": "和历",
+ "islamic-civil": "伊斯兰希吉来日历",
+ "islamicc": "伊斯兰希吉来日历",
+ "ethioaa": "埃塞俄比亚阿米特阿莱姆日历",
+ "ethiopic-amete-alem": "埃塞俄比亚阿米特阿莱姆日历",
+ },
+ short: {},
+ narrow: {},
+ },
+};
+
+for (let [locale, localeTests] of Object.entries(tests)) {
+ for (let [style, styleTests] of Object.entries(localeTests)) {
+ let dn = new Intl.DisplayNames(locale, {type: "calendar", style});
+
+ let resolved = dn.resolvedOptions();
+ assertEq(resolved.locale, locale);
+ assertEq(resolved.style, style);
+ assertEq(resolved.type, "calendar");
+ assertEq(resolved.fallback, "code");
+
+ let inheritedTests = {...localeTests.long, ...localeTests.short, ...localeTests.narrow};
+ for (let [calendar, expected] of Object.entries({...inheritedTests, ...styleTests})) {
+ assertEq(dn.of(calendar), expected);
+
+ // Also works with objects.
+ assertEq(dn.of(Object(calendar)), expected);
+ }
+ }
+}
+
+{
+ let dn = new Intl.DisplayNames("en", {type: "calendar"});
+
+ // Performs ToString on the input and then validates the stringified result.
+ assertThrowsInstanceOf(() => dn.of(), RangeError);
+ assertThrowsInstanceOf(() => dn.of(undefined), RangeError);
+ assertThrowsInstanceOf(() => dn.of(Symbol()), TypeError);
+ assertThrowsInstanceOf(() => dn.of(0), RangeError);
+
+ // Throws an error if |code| isn't a well-formed calendar type.
+ assertThrowsInstanceOf(() => dn.of("gregorian"), RangeError);
+ assertThrowsInstanceOf(() => dn.of("grëgory"), RangeError);
+ assertThrowsInstanceOf(() => dn.of("grēgory"), RangeError);
+}
+
+// Test fallback behaviour.
+{
+ let dn1 = new Intl.DisplayNames("en", {type: "calendar"});
+ let dn2 = new Intl.DisplayNames("en", {type: "calendar", fallback: "code"});
+ let dn3 = new Intl.DisplayNames("en", {type: "calendar", fallback: "none"});
+
+ assertEq(dn1.resolvedOptions().fallback, "code");
+ assertEq(dn2.resolvedOptions().fallback, "code");
+ assertEq(dn3.resolvedOptions().fallback, "none");
+
+ // "invalid" isn't a known calendar type.
+ assertEq(dn1.of("invalid"), "invalid");
+ assertEq(dn2.of("invalid"), "invalid");
+ assertEq(dn3.of("invalid"), undefined);
+
+ // The returned fallback is in canonical case.
+ assertEq(dn1.of("INVALID"), "invalid");
+ assertEq(dn2.of("INVALID"), "invalid");
+ assertEq(dn3.of("INVALID"), undefined);
+}
+
+// Test when case isn't canonical.
+{
+ let dn = new Intl.DisplayNames("en", {type: "calendar", fallback: "none"});
+
+ assertEq(dn.of("gregory"), "Gregorian Calendar");
+ assertEq(dn.of("GREGORY"), "Gregorian Calendar");
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Intl/DisplayNames/currency.js b/js/src/tests/non262/Intl/DisplayNames/currency.js
new file mode 100644
index 0000000000..1571249106
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/currency.js
@@ -0,0 +1,150 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl'))
+
+const tests = {
+ "en": {
+ long: {
+ "USD": "US Dollar",
+ "EUR": "Euro",
+ "FRF": "French Franc",
+ "CNY": "Chinese Yuan",
+ "XAU": "Gold",
+ },
+ short: {
+ "USD": "$",
+ "EUR": "€",
+ "FRF": "FRF",
+ "CNY": "CN¥",
+ "XAU": "XAU",
+ },
+ narrow: {
+ "USD": "USD",
+ "EUR": "EUR",
+ "CNY": "CNY",
+ },
+ },
+ "de": {
+ long: {
+ "USD": "US-Dollar",
+ "EUR": "Euro",
+ "FRF": "Französischer Franc",
+ "CNY": "Renminbi Yuan",
+ "XAU": "Unze Gold",
+ },
+ short: {
+ "USD": "$",
+ "EUR": "€",
+ "FRF": "FRF",
+ "CNY": "CN¥",
+ "XAU": "XAU",
+ },
+ narrow: {
+ "CNY": "¥",
+ },
+ },
+ "fr": {
+ long: {
+ "USD": "dollar des États-Unis",
+ "EUR": "euro",
+ "FRF": "franc français",
+ "CNY": "yuan renminbi chinois",
+ "XAU": "or",
+ },
+ short: {
+ "USD": "$US",
+ "EUR": "€",
+ "FRF": "F",
+ "CNY": "CNY",
+ "XAU": "XAU",
+ },
+ narrow: {
+ "USD": "$",
+ "CNY": "¥",
+ },
+ },
+ "zh": {
+ long: {
+ "USD": "美元",
+ "EUR": "欧元",
+ "FRF": "法国法郎",
+ "CNY": "人民币",
+ "XAU": "黄金",
+ },
+ short: {
+ "USD": "US$",
+ "EUR": "€",
+ "FRF": "FRF",
+ "CNY": "¥",
+ "XAU": "XAU",
+ },
+ narrow: {
+ "USD": "$",
+ },
+ },
+};
+
+for (let [locale, localeTests] of Object.entries(tests)) {
+ for (let [style, styleTests] of Object.entries(localeTests)) {
+ let dn = new Intl.DisplayNames(locale, {type: "currency", style});
+
+ let resolved = dn.resolvedOptions();
+ assertEq(resolved.locale, locale);
+ assertEq(resolved.style, style);
+ assertEq(resolved.type, "currency");
+ assertEq(resolved.fallback, "code");
+
+ let inheritedTests = {...localeTests.long, ...localeTests.short, ...localeTests.narrow};
+ for (let [currency, expected] of Object.entries({...inheritedTests, ...styleTests})) {
+ assertEq(dn.of(currency), expected);
+
+ // Also works with objects.
+ assertEq(dn.of(Object(currency)), expected);
+ }
+ }
+}
+
+{
+ let dn = new Intl.DisplayNames("en", {type: "currency"});
+
+ // Performs ToString on the input and then validates the stringified result.
+ assertThrowsInstanceOf(() => dn.of(), RangeError);
+ assertThrowsInstanceOf(() => dn.of(null), RangeError);
+ assertThrowsInstanceOf(() => dn.of(Symbol()), TypeError);
+ assertThrowsInstanceOf(() => dn.of(0), RangeError);
+
+ // Throws an error if |code| isn't a well-formed currency code.
+ assertThrowsInstanceOf(() => dn.of("us"), RangeError);
+ assertThrowsInstanceOf(() => dn.of("euro"), RangeError);
+ assertThrowsInstanceOf(() => dn.of("€uro"), RangeError);
+}
+
+// Test fallback behaviour.
+{
+ let dn1 = new Intl.DisplayNames("en", {type: "currency"});
+ let dn2 = new Intl.DisplayNames("en", {type: "currency", fallback: "code"});
+ let dn3 = new Intl.DisplayNames("en", {type: "currency", fallback: "none"});
+
+ assertEq(dn1.resolvedOptions().fallback, "code");
+ assertEq(dn2.resolvedOptions().fallback, "code");
+ assertEq(dn3.resolvedOptions().fallback, "none");
+
+ // "AAA" is not a registered currency code.
+ assertEq(dn1.of("AAA"), "AAA");
+ assertEq(dn2.of("AAA"), "AAA");
+ assertEq(dn3.of("AAA"), undefined);
+
+ // The returned fallback is in canonical case.
+ assertEq(dn1.of("aaa"), "AAA");
+ assertEq(dn2.of("aaa"), "AAA");
+ assertEq(dn3.of("aaa"), undefined);
+}
+
+// Test when case isn't canonical.
+{
+ let dn = new Intl.DisplayNames("en", {type: "currency", fallback: "none"});
+
+ assertEq(dn.of("USD"), "US Dollar");
+ assertEq(dn.of("usd"), "US Dollar");
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Intl/DisplayNames/dateTimeField.js b/js/src/tests/non262/Intl/DisplayNames/dateTimeField.js
new file mode 100644
index 0000000000..94bdf53899
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/dateTimeField.js
@@ -0,0 +1,176 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl'))
+
+const tests = {
+ "en": {
+ long: {
+ "era": "era",
+ "year": "year",
+ "quarter": "quarter",
+ "month": "month",
+ "weekOfYear": "week",
+ "weekday": "day of the week",
+ "day": "day",
+ "dayPeriod": "AM/PM",
+ "hour": "hour",
+ "minute": "minute",
+ "second": "second",
+ "timeZoneName": "time zone",
+ },
+ short: {
+ "year": "yr.",
+ "quarter": "qtr.",
+ "month": "mo.",
+ "weekOfYear": "wk.",
+ "weekday": "day of wk.",
+ "dayPeriod": "AM/PM",
+ "hour": "hr.",
+ "minute": "min.",
+ "second": "sec.",
+ "timeZoneName": "zone",
+ },
+ narrow: {
+ "year": "yr",
+ "quarter": "qtr",
+ "month": "mo",
+ "weekOfYear": "wk",
+ "hour": "hr",
+ "minute": "min",
+ "second": "sec",
+ },
+ },
+ "de": {
+ long: {
+ "era": "Epoche",
+ "year": "Jahr",
+ "quarter": "Quartal",
+ "month": "Monat",
+ "weekOfYear": "Woche",
+ "weekday": "Wochentag",
+ "day": "Tag",
+ "dayPeriod": "Tageshälfte",
+ "hour": "Stunde",
+ "minute": "Minute",
+ "second": "Sekunde",
+ "timeZoneName": "Zeitzone",
+ },
+ short: {
+ "era": "Epoche",
+ "year": "Jahr",
+ "quarter": "Quart.",
+ "month": "Monat",
+ "weekOfYear": "Woche",
+ "weekday": "Wochentag",
+ "day": "Tag",
+ "dayPeriod": "Tageshälfte",
+ "hour": "Std.",
+ "minute": "Min.",
+ "second": "Sek.",
+ "timeZoneName": "Zeitzone",
+ },
+ narrow: {
+ "era": "E",
+ "year": "J",
+ "quarter": "Q",
+ "month": "M",
+ "weekOfYear": "W",
+ "weekday": "Wochent.",
+ "dayPeriod": "Tagesh.",
+ "timeZoneName": "Zeitz.",
+ },
+ },
+ "fr": {
+ long: {
+ "era": "ère",
+ "year": "année",
+ "quarter": "trimestre",
+ "month": "mois",
+ "weekOfYear": "semaine",
+ "weekday": "jour de la semaine",
+ "day": "jour",
+ "dayPeriod": "cadran",
+ "hour": "heure",
+ "minute": "minute",
+ "second": "seconde",
+ "timeZoneName": "fuseau horaire",
+ },
+ short: {
+ "year": "an",
+ "quarter": "trim.",
+ "month": "m.",
+ "weekOfYear": "sem.",
+ "weekday": "j (sem.)",
+ "day": "j",
+ "hour": "h",
+ "minute": "min",
+ "second": "s",
+ },
+ narrow: {
+ "year": "a",
+ },
+ },
+ "zh": {
+ long: {
+ "era": "纪元",
+ "year": "年",
+ "quarter": "季度",
+ "month": "月",
+ "weekOfYear": "周",
+ "weekday": "工作日",
+ "day": "日",
+ "dayPeriod": "上午/下午",
+ "hour": "小时",
+ "minute": "分钟",
+ "second": "秒",
+ "timeZoneName": "时区",
+ },
+ short: {
+ "quarter": "季",
+ "minute": "分",
+ },
+ narrow: {},
+ },
+};
+
+for (let [locale, localeTests] of Object.entries(tests)) {
+ for (let [style, styleTests] of Object.entries(localeTests)) {
+ let dn = new Intl.DisplayNames(locale, {type: "dateTimeField", style});
+
+ let resolved = dn.resolvedOptions();
+ assertEq(resolved.locale, locale);
+ assertEq(resolved.style, style);
+ assertEq(resolved.type, "dateTimeField");
+ assertEq(resolved.fallback, "code");
+
+ let inheritedTests = {...localeTests.long, ...localeTests.short, ...localeTests.narrow};
+ for (let [field, expected] of Object.entries({...inheritedTests, ...styleTests})) {
+ assertEq(dn.of(field), expected);
+
+ // Also works with objects.
+ assertEq(dn.of(Object(field)), expected);
+ }
+ }
+}
+
+{
+ let dn = new Intl.DisplayNames("en", {type: "dateTimeField"});
+
+ // Performs ToString on the input and then validates the stringified result.
+ assertThrowsInstanceOf(() => dn.of(), RangeError);
+ assertThrowsInstanceOf(() => dn.of(null), RangeError);
+ assertThrowsInstanceOf(() => dn.of(Symbol()), TypeError);
+ assertThrowsInstanceOf(() => dn.of(0), RangeError);
+ assertThrowsInstanceOf(() => dn.of(1), RangeError);
+
+ // Throws an error if not one of ["era", "year", "quarter", "month", "weekOfYear", "weekday",
+ // "day", "dayPeriod", "hour", "minute", "second", "timeZoneName"].
+ assertThrowsInstanceOf(() => dn.of(""), RangeError);
+ assertThrowsInstanceOf(() => dn.of("ERA"), RangeError);
+ assertThrowsInstanceOf(() => dn.of("Era"), RangeError);
+ assertThrowsInstanceOf(() => dn.of("era\0"), RangeError);
+ assertThrowsInstanceOf(() => dn.of("dayperiod"), RangeError);
+ assertThrowsInstanceOf(() => dn.of("day-period"), RangeError);
+ assertThrowsInstanceOf(() => dn.of("timezoneName"), RangeError);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Intl/DisplayNames/dayPeriod.js b/js/src/tests/non262/Intl/DisplayNames/dayPeriod.js
new file mode 100644
index 0000000000..cfeafdf5ee
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/dayPeriod.js
@@ -0,0 +1,80 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl')||!this.hasOwnProperty('addIntlExtras'))
+
+addMozIntlDisplayNames(this);
+
+const tests = {
+ "en": {
+ long: {
+ "am": "AM",
+ "pm": "PM",
+ },
+ short: {},
+ narrow: {},
+ },
+ "de": {
+ long: {
+ "am": "AM",
+ "pm": "PM",
+ },
+ short: {},
+ narrow: {},
+ },
+ "fr": {
+ long: {
+ "am": "AM",
+ "pm": "PM",
+ },
+ short: {},
+ narrow: {},
+ },
+ "zh": {
+ long: {
+ "am": "上午",
+ "pm": "下午",
+ },
+ short: {},
+ narrow: {},
+ },
+};
+
+for (let [locale, localeTests] of Object.entries(tests)) {
+ let defaultCalendar = new Intl.DateTimeFormat(locale).resolvedOptions().calendar;
+
+ for (let [style, styleTests] of Object.entries(localeTests)) {
+ let dn = new Intl.DisplayNames(locale, {type: "dayPeriod", style});
+
+ let resolved = dn.resolvedOptions();
+ assertEq(resolved.locale, locale);
+ assertEq(resolved.calendar, defaultCalendar);
+ assertEq(resolved.style, style);
+ assertEq(resolved.type, "dayPeriod");
+ assertEq(resolved.fallback, "code");
+
+ let inheritedTests = {...localeTests.long, ...localeTests.short, ...localeTests.narrow};
+ for (let [dayPeriod, expected] of Object.entries({...inheritedTests, ...styleTests})) {
+ assertEq(dn.of(dayPeriod), expected);
+
+ // Also works with objects.
+ assertEq(dn.of(Object(dayPeriod)), expected);
+ }
+ }
+}
+
+{
+ let dn = new Intl.DisplayNames("en", {type: "dayPeriod"});
+
+ // Performs ToString on the input and then validates the stringified result.
+ assertThrowsInstanceOf(() => dn.of(), RangeError);
+ assertThrowsInstanceOf(() => dn.of(null), RangeError);
+ assertThrowsInstanceOf(() => dn.of(Symbol()), TypeError);
+ assertThrowsInstanceOf(() => dn.of(0), RangeError);
+ assertThrowsInstanceOf(() => dn.of(1), RangeError);
+
+ // Throws an error if not one of ["am", "pm"].
+ assertThrowsInstanceOf(() => dn.of(""), RangeError);
+ assertThrowsInstanceOf(() => dn.of("AM"), RangeError);
+ assertThrowsInstanceOf(() => dn.of("PM"), RangeError);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Intl/DisplayNames/language-dialect.js b/js/src/tests/non262/Intl/DisplayNames/language-dialect.js
new file mode 100644
index 0000000000..c2999bd673
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/language-dialect.js
@@ -0,0 +1,104 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl'))
+
+const tests = {
+ "en": {
+ long: {
+ "de": "German",
+ "de-AT": "Austrian German",
+ "de-1996": "German (German orthography of 1996)",
+ "en": "English",
+ "en-Hant-GB": "British English (Traditional)",
+ "en-Hans-US": "American English (Simplified)",
+ "fr": "French",
+ "nl-BE": "Flemish",
+ "cr-Cans": "Cree (Unified Canadian Aboriginal Syllabics)",
+ },
+ short: {
+ "en-Hant-GB": "UK English (Traditional)",
+ "en-Hans-US": "US English (Simplified)",
+ "cr-Cans": "Cree (UCAS)",
+ },
+ narrow: {},
+ },
+ "de": {
+ long: {
+ "de": "Deutsch",
+ "de-AT": "Österreichisches Deutsch",
+ "de-1996": "Deutsch (Neue deutsche Rechtschreibung)",
+ "en": "Englisch",
+ "en-Hant-GB": "Englisch (Traditionell, Vereinigtes Königreich)",
+ "en-Hans-US": "Englisch (Vereinfacht, Vereinigte Staaten)",
+ "fr": "Französisch",
+ "nl-BE": "Flämisch",
+ },
+ short: {
+ "en-Hant-GB": "Englisch (GB) (Traditionell)",
+ "en-Hans-US": "Englisch (USA) (Vereinfacht)",
+ },
+ narrow: {},
+ },
+ "fr": {
+ long: {
+ "de": "allemand",
+ "de-AT": "allemand autrichien",
+ "de-1996": "allemand (orthographe allemande de 1996)",
+ "en": "anglais",
+ "en-Hant-GB": "anglais britannique (traditionnel)",
+ "en-Hans-US": "anglais américain (simplifié)",
+ "fr": "français",
+ "nl-BE": "flamand",
+ },
+ short: {
+ "en-Hant-GB": "anglais britannique (traditionnel)",
+ "en-Hans-US": "anglais américain (simplifié)",
+ },
+ narrow: {},
+ },
+ "zh": {
+ long: {
+ "zh": "中文",
+ "zh-Hant": "繁体中文",
+ "zh-Hant-CN": "繁体中文(中国)",
+ "zh-Hans-HK": "简体中文(中国香港特别行政区)",
+ },
+ short: {
+ "zh-Hans-HK": "简体中文(香港)"
+ },
+ narrow: {},
+ },
+ "ar": {
+ long: {
+ "ar": "العربية",
+ "ar-SA": "العربية (المملكة العربية السعودية)",
+ "zh-MO": "الصينية (منطقة ماكاو الإدارية الخاصة)",
+ },
+ short: {
+ "zh-MO": "الصينية (مكاو)",
+ },
+ narrow: {},
+ },
+};
+
+for (let [locale, localeTests] of Object.entries(tests)) {
+ for (let [style, styleTests] of Object.entries(localeTests)) {
+ let dn = new Intl.DisplayNames(locale, {type: "language", languageDisplay: "dialect", style});
+
+ let resolved = dn.resolvedOptions();
+ assertEq(resolved.locale, locale);
+ assertEq(resolved.style, style);
+ assertEq(resolved.type, "language");
+ assertEq(resolved.languageDisplay, "dialect");
+ assertEq(resolved.fallback, "code");
+
+ let inheritedTests = {...localeTests.long, ...localeTests.short, ...localeTests.narrow};
+ for (let [language, expected] of Object.entries({...inheritedTests, ...styleTests})) {
+ assertEq(dn.of(language), expected);
+
+ // Also works with objects.
+ assertEq(dn.of(Object(language)), expected);
+ }
+ }
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Intl/DisplayNames/language.js b/js/src/tests/non262/Intl/DisplayNames/language.js
new file mode 100644
index 0000000000..48fb72056e
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/language.js
@@ -0,0 +1,205 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl'))
+
+const tests = {
+ "en": {
+ long: {
+ "de": "German",
+ "de-AT": "German (Austria)",
+ "de-1996": "German (German orthography of 1996)",
+ "en": "English",
+ "en-Hant-GB": "English (Traditional, United Kingdom)",
+ "en-Hans-US": "English (Simplified, United States)",
+ "fr": "French",
+ "nl-BE": "Dutch (Belgium)",
+ "cr-Cans": "Cree (Unified Canadian Aboriginal Syllabics)",
+ },
+ short: {
+ "en-Hant-GB": "English (Traditional, UK)",
+ "en-Hans-US": "English (Simplified, US)",
+ "cr-Cans": "Cree (UCAS)",
+ },
+ narrow: {},
+ },
+ "de": {
+ long: {
+ "de": "Deutsch",
+ "de-AT": "Deutsch (Österreich)",
+ "de-1996": "Deutsch (Neue deutsche Rechtschreibung)",
+ "en": "Englisch",
+ "en-Hant-GB": "Englisch (Traditionell, Vereinigtes Königreich)",
+ "en-Hans-US": "Englisch (Vereinfacht, Vereinigte Staaten)",
+ "fr": "Französisch",
+ "nl-BE": "Niederländisch (Belgien)",
+ },
+ short: {
+ "en-Hant-GB": "Englisch (Traditionell, UK)",
+ "en-Hans-US": "Englisch (Vereinfacht, USA)",
+ },
+ narrow: {},
+ },
+ "fr": {
+ long: {
+ "de": "allemand",
+ "de-AT": "allemand (Autriche)",
+ "de-1996": "allemand (orthographe allemande de 1996)",
+ "en": "anglais",
+ "en-Hant-GB": "anglais (traditionnel, Royaume-Uni)",
+ "en-Hans-US": "anglais (simplifié, États-Unis)",
+ "fr": "français",
+ "nl-BE": "néerlandais (Belgique)",
+ },
+ short: {
+ "en-Hant-GB": "anglais (traditionnel, R.-U.)",
+ "en-Hans-US": "anglais (simplifié, É.-U.)",
+ },
+ narrow: {},
+ },
+ "zh": {
+ long: {
+ "zh": "中文",
+ "zh-Hant": "中文(繁体)",
+ "zh-Hant-CN": "中文(繁体,中国)",
+ "zh-Hans-HK": "中文(简体,中国香港特别行政区)",
+ },
+ short: {
+ "zh-Hans-HK": "中文(简体,香港)"
+ },
+ narrow: {},
+ },
+ "ar": {
+ long: {
+ "ar": "العربية",
+ "ar-SA": "العربية (المملكة العربية السعودية)",
+ "zh-MO": "الصينية (منطقة ماكاو الإدارية الخاصة)",
+ },
+ short: {
+ "zh-MO": "الصينية (مكاو)",
+ },
+ narrow: {},
+ },
+};
+
+for (let [locale, localeTests] of Object.entries(tests)) {
+ for (let [style, styleTests] of Object.entries(localeTests)) {
+ let dn = new Intl.DisplayNames(locale, {type: "language", languageDisplay: "standard", style});
+
+ let resolved = dn.resolvedOptions();
+ assertEq(resolved.locale, locale);
+ assertEq(resolved.style, style);
+ assertEq(resolved.type, "language");
+ assertEq(resolved.languageDisplay, "standard");
+ assertEq(resolved.fallback, "code");
+
+ let inheritedTests = {...localeTests.long, ...localeTests.short, ...localeTests.narrow};
+ for (let [language, expected] of Object.entries({...inheritedTests, ...styleTests})) {
+ assertEq(dn.of(language), expected);
+
+ // Also works with objects.
+ assertEq(dn.of(Object(language)), expected);
+ }
+ }
+}
+
+{
+ let dn = new Intl.DisplayNames("en", {type: "language"});
+
+ // Performs ToString on the input and then validates the stringified result.
+ assertThrowsInstanceOf(() => dn.of(), RangeError);
+ assertThrowsInstanceOf(() => dn.of(null), RangeError);
+ assertThrowsInstanceOf(() => dn.of(Symbol()), TypeError);
+ assertThrowsInstanceOf(() => dn.of(0), RangeError);
+
+ // Throws an error if |code| can't be parsed as a `unicode_language_id` production.
+ assertThrowsInstanceOf(() => dn.of("en-"), RangeError);
+ assertThrowsInstanceOf(() => dn.of("en-u-ca-gregory"), RangeError);
+ assertThrowsInstanceOf(() => dn.of("en-x-private"), RangeError);
+}
+
+// Test fallback behaviour.
+{
+ let dn1 = new Intl.DisplayNames("en", {type: "language"});
+ let dn2 = new Intl.DisplayNames("en", {type: "language", fallback: "code"});
+ let dn3 = new Intl.DisplayNames("en", {type: "language", fallback: "none"});
+
+ assertEq(dn1.resolvedOptions().fallback, "code");
+ assertEq(dn2.resolvedOptions().fallback, "code");
+ assertEq(dn3.resolvedOptions().fallback, "none");
+
+ // "aaa" is not a registered language code.
+ assertEq(dn1.of("aaa"), "aaa");
+ assertEq(dn2.of("aaa"), "aaa");
+ assertEq(dn3.of("aaa"), undefined);
+
+ // "aaa" is not a registered language code.
+ assertEq(dn1.of("aaa-Latn"), "aaa-Latn");
+ assertEq(dn2.of("aaa-Latn"), "aaa-Latn");
+ assertEq(dn3.of("aaa-Latn"), undefined);
+
+ // "Aaaa" is not a registered script code.
+ assertEq(dn1.of("en-Aaaa"), "en-Aaaa");
+ assertEq(dn2.of("en-Aaaa"), "en-Aaaa");
+ assertEq(dn3.of("en-Aaaa"), undefined);
+
+ // "AA" is not a registered region code.
+ assertEq(dn1.of("en-AA"), "en-AA");
+ assertEq(dn2.of("en-AA"), "en-AA");
+ assertEq(dn3.of("en-AA"), undefined);
+
+ // "XZ" doesn't have any localised names.
+ assertEq(dn1.of("en-XZ"), "en-XZ");
+ assertEq(dn2.of("en-XZ"), "en-XZ");
+ assertEq(dn3.of("en-XZ"), undefined);
+
+ // "998" is canonicalised to "XZ".
+ assertEq(dn1.of("en-998"), "en-XZ");
+ assertEq(dn2.of("en-998"), "en-XZ");
+ assertEq(dn3.of("en-998"), undefined);
+
+ // The returned fallback is in canonical case.
+ assertEq(dn1.of("AAA"), "aaa");
+ assertEq(dn2.of("AAA"), "aaa");
+ assertEq(dn3.of("AAA"), undefined);
+
+ assertEq(dn1.of("En-aaaa"), "en-Aaaa");
+ assertEq(dn2.of("En-aaaa"), "en-Aaaa");
+ assertEq(dn3.of("En-aaaa"), undefined);
+
+ assertEq(dn1.of("EN-aa"), "en-AA");
+ assertEq(dn2.of("EN-aa"), "en-AA");
+ assertEq(dn3.of("EN-aa"), undefined);
+}
+
+// Ensure language tag canonicalisation is performed.
+{
+ let dn = new Intl.DisplayNames("en", {type: "language", fallback: "none"});
+
+ assertEq(dn.of("ru-RU"), "Russian (Russia)");
+
+ // ICU's canonicalisation supports "SU" -> "RU".
+ assertEq(Intl.getCanonicalLocales("ru-SU")[0], "ru-RU");
+ assertEq(dn.of("ru-SU"), "Russian (Russia)");
+
+ // ICU's canonicalisation doesn't support "172" -> "RU".
+ assertEq(Intl.getCanonicalLocales("ru-172")[0], "ru-RU");
+ assertEq(dn.of("ru-172"), "Russian (Russia)");
+}
+
+// Test when case isn't canonical.
+{
+ let dn = new Intl.DisplayNames("en", {type: "language", fallback: "none"});
+
+ assertEq(dn.of("IT-LATN-IT"), "Italian (Latin, Italy)");
+ assertEq(dn.of("it-latn-it"), "Italian (Latin, Italy)");
+}
+
+// resolvedOptions() only outputs "languageDisplay" when the type is "language".
+{
+ let dn1 = new Intl.DisplayNames("en", {type: "language"});
+ let dn2 = new Intl.DisplayNames("en", {type: "script"});
+
+ assertEq(dn1.resolvedOptions().languageDisplay, "dialect");
+ assertEq(dn2.resolvedOptions().hasOwnProperty("languageDisplay"), false);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Intl/DisplayNames/month-calendar.js b/js/src/tests/non262/Intl/DisplayNames/month-calendar.js
new file mode 100644
index 0000000000..9a7d9abdaa
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/month-calendar.js
@@ -0,0 +1,18 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl')||!this.hasOwnProperty('addIntlExtras'))
+
+addMozIntlDisplayNames(this);
+
+let dn1 = new Intl.DisplayNames("en", {type: "month", calendar: "gregory"});
+assertEq(dn1.of(1), "January");
+assertEq(dn1.resolvedOptions().calendar, "gregory");
+
+let dn2 = new Intl.DisplayNames("en", {type: "month", calendar: "hebrew"});
+assertEq(dn2.of(1), "Tishri");
+assertEq(dn2.resolvedOptions().calendar, "hebrew");
+
+let dn3 = new Intl.DisplayNames("en", {type: "month", calendar: "islamicc"});
+assertEq(dn3.of(1), "Muharram");
+assertEq(dn3.resolvedOptions().calendar, "islamic-civil");
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Intl/DisplayNames/month.js b/js/src/tests/non262/Intl/DisplayNames/month.js
new file mode 100644
index 0000000000..0bd7a02a80
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/month.js
@@ -0,0 +1,104 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl')||!this.hasOwnProperty('addIntlExtras'))
+
+addMozIntlDisplayNames(this);
+
+const tests = {
+ "en": {
+ long: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", 13],
+ short: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 13],
+ narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D", 13],
+ },
+ "de": {
+ long: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember", 13],
+ short: ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez", 13],
+ narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D", 13],
+ },
+ "fr": {
+ long: ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre", 13],
+ short: ["janv.", "févr.", "mars", "avr.", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc.", 13],
+ narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D", 13],
+ },
+ "zh": {
+ long: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月", 13],
+ short: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月", 13],
+ narrow: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", 13],
+ },
+ "zh-u-ca-chinese": {
+ long: ["正月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "腊月", 13],
+ short: ["正月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "腊月", 13],
+ narrow: ["正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "冬", "腊", 13],
+ },
+ "en-u-ca-hebrew": {
+ long: ["Tishri", "Heshvan", "Kislev", "Tevet", "Shevat", "Adar I", "Adar", "Nisan", "Iyar", "Sivan", "Tamuz", "Av", "Elul"],
+ short: ["Tishri", "Heshvan", "Kislev", "Tevet", "Shevat", "Adar I", "Adar", "Nisan", "Iyar", "Sivan", "Tamuz", "Av", "Elul"],
+ narrow: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"],
+ },
+};
+
+for (let [locale, localeTests] of Object.entries(tests)) {
+ let defaultCalendar = new Intl.DateTimeFormat(locale).resolvedOptions().calendar;
+
+ for (let [style, styleTests] of Object.entries(localeTests)) {
+ let dn = new Intl.DisplayNames(locale, {type: "month", style});
+
+ let resolved = dn.resolvedOptions();
+ assertEq(resolved.locale, locale);
+ assertEq(resolved.calendar, defaultCalendar);
+ assertEq(resolved.style, style);
+ assertEq(resolved.type, "month");
+ assertEq(resolved.fallback, "code");
+
+ for (let i = 0; i < 13; i++) {
+ assertEq(dn.of(i + 1), String(styleTests[i]));
+
+ // Also works with strings.
+ assertEq(dn.of(String(i + 1)), String(styleTests[i]));
+
+ // Also works with objects.
+ assertEq(dn.of(Object(i + 1)), String(styleTests[i]));
+ }
+ }
+}
+
+{
+ let dn = new Intl.DisplayNames("en", {type: "month"});
+
+ // Performs ToString on the input and then validates the stringified result.
+ assertThrowsInstanceOf(() => dn.of(), RangeError);
+ assertThrowsInstanceOf(() => dn.of(null), RangeError);
+ assertThrowsInstanceOf(() => dn.of(Symbol()), TypeError);
+
+ // Throws an error if |code| isn't an integer.
+ assertThrowsInstanceOf(() => dn.of(1.5), RangeError);
+ assertThrowsInstanceOf(() => dn.of(-Infinity), RangeError);
+ assertThrowsInstanceOf(() => dn.of(Infinity), RangeError);
+ assertThrowsInstanceOf(() => dn.of(NaN), RangeError);
+
+ // Throws an error if outside of [1, 13].
+ assertThrowsInstanceOf(() => dn.of(-1), RangeError);
+ assertThrowsInstanceOf(() => dn.of(0), RangeError);
+ assertThrowsInstanceOf(() => dn.of(14), RangeError);
+}
+
+// Test fallback behaviour.
+{
+ let dn1 = new Intl.DisplayNames("en", {type: "month"});
+ let dn2 = new Intl.DisplayNames("en", {type: "month", fallback: "code"});
+ let dn3 = new Intl.DisplayNames("en", {type: "month", fallback: "none"});
+
+ assertEq(dn1.resolvedOptions().fallback, "code");
+ assertEq(dn2.resolvedOptions().fallback, "code");
+ assertEq(dn3.resolvedOptions().fallback, "none");
+
+ assertEq(dn1.resolvedOptions().calendar, "gregory");
+ assertEq(dn2.resolvedOptions().calendar, "gregory");
+ assertEq(dn3.resolvedOptions().calendar, "gregory");
+
+ // The Gregorian calendar doesn't have a thirteenth month.
+ assertEq(dn1.of("13"), "13");
+ assertEq(dn2.of("13"), "13");
+ assertEq(dn3.of("13"), undefined);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Intl/DisplayNames/quarter.js b/js/src/tests/non262/Intl/DisplayNames/quarter.js
new file mode 100644
index 0000000000..f74b3b439a
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/quarter.js
@@ -0,0 +1,74 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl')||!this.hasOwnProperty('addIntlExtras'))
+
+addMozIntlDisplayNames(this);
+
+const tests = {
+ "en": {
+ long: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"],
+ short: ["Q1", "Q2", "Q3", "Q4"],
+ narrow: ["1", "2", "3", "4"],
+ },
+ "de": {
+ long: ["1. Quartal", "2. Quartal", "3. Quartal", "4. Quartal"],
+ short: ["Q1", "Q2", "Q3", "Q4"],
+ narrow: ["1", "2", "3", "4"],
+ },
+ "fr": {
+ long: ["1er trimestre", "2e trimestre", "3e trimestre", "4e trimestre"],
+ short: ["T1", "T2", "T3", "T4"],
+ narrow: ["1", "2", "3", "4"],
+ },
+ "zh": {
+ long: ["第一季度", "第二季度", "第三季度", "第四季度"],
+ short: ["1季度", "2季度", "3季度", "4季度"],
+ narrow: ["1", "2", "3", "4"],
+ },
+};
+
+for (let [locale, localeTests] of Object.entries(tests)) {
+ let defaultCalendar = new Intl.DateTimeFormat(locale).resolvedOptions().calendar;
+
+ for (let [style, styleTests] of Object.entries(localeTests)) {
+ let dn = new Intl.DisplayNames(locale, {type: "quarter", style});
+
+ let resolved = dn.resolvedOptions();
+ assertEq(resolved.locale, locale);
+ assertEq(resolved.calendar, defaultCalendar);
+ assertEq(resolved.style, style);
+ assertEq(resolved.type, "quarter");
+ assertEq(resolved.fallback, "code");
+
+ for (let i = 0; i < 4; i++) {
+ assertEq(dn.of(i + 1), styleTests[i]);
+
+ // Also works with strings.
+ assertEq(dn.of(String(i + 1)), styleTests[i]);
+
+ // Also works with objects.
+ assertEq(dn.of(Object(i + 1)), styleTests[i]);
+ }
+ }
+}
+
+{
+ let dn = new Intl.DisplayNames("en", {type: "quarter"});
+
+ // Performs ToString on the input and then validates the stringified result.
+ assertThrowsInstanceOf(() => dn.of(), RangeError);
+ assertThrowsInstanceOf(() => dn.of(null), RangeError);
+ assertThrowsInstanceOf(() => dn.of(Symbol()), TypeError);
+
+ // Throws an error if |code| isn't an integer.
+ assertThrowsInstanceOf(() => dn.of(1.5), RangeError);
+ assertThrowsInstanceOf(() => dn.of(-Infinity), RangeError);
+ assertThrowsInstanceOf(() => dn.of(Infinity), RangeError);
+ assertThrowsInstanceOf(() => dn.of(NaN), RangeError);
+
+ // Throws an error if outside of [1, 4].
+ assertThrowsInstanceOf(() => dn.of(-1), RangeError);
+ assertThrowsInstanceOf(() => dn.of(0), RangeError);
+ assertThrowsInstanceOf(() => dn.of(5), RangeError);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Intl/DisplayNames/region.js b/js/src/tests/non262/Intl/DisplayNames/region.js
new file mode 100644
index 0000000000..2d1bfe58d8
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/region.js
@@ -0,0 +1,157 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl'))
+
+const tests = {
+ "en": {
+ long: {
+ "DE": "Germany",
+ "GB": "United Kingdom",
+ "US": "United States",
+ "FR": "France",
+ },
+ short: {
+ "GB": "UK",
+ "US": "US",
+ },
+ narrow: {},
+ },
+ "de": {
+ long: {
+ "DE": "Deutschland",
+ "GB": "Vereinigtes Königreich",
+ "US": "Vereinigte Staaten",
+ "FR": "Frankreich",
+ },
+ short: {
+ "GB": "UK",
+ "US": "USA",
+ },
+ narrow: {},
+ },
+ "fr": {
+ long: {
+ "DE": "Allemagne",
+ "GB": "Royaume-Uni",
+ "US": "États-Unis",
+ "FR": "France",
+ },
+ short: {
+ "GB": "R.-U.",
+ "US": "É.-U.",
+ },
+ narrow: {},
+ },
+ "zh": {
+ long: {
+ "CN": "中国",
+ "HK": "中国香港特别行政区",
+ },
+ short: {
+ "HK": "香港"
+ },
+ narrow: {},
+ },
+ "ar": {
+ long: {
+ "SA": "المملكة العربية السعودية",
+ "MO": "منطقة ماكاو الإدارية الخاصة",
+ },
+ short: {
+ "MO": "مكاو",
+ },
+ narrow: {},
+ },
+};
+
+for (let [locale, localeTests] of Object.entries(tests)) {
+ for (let [style, styleTests] of Object.entries(localeTests)) {
+ let dn = new Intl.DisplayNames(locale, {type: "region", style});
+
+ let resolved = dn.resolvedOptions();
+ assertEq(resolved.locale, locale);
+ assertEq(resolved.style, style);
+ assertEq(resolved.type, "region");
+ assertEq(resolved.fallback, "code");
+
+ let inheritedTests = {...localeTests.long, ...localeTests.short, ...localeTests.narrow};
+ for (let [region, expected] of Object.entries({...inheritedTests, ...styleTests})) {
+ assertEq(dn.of(region), expected);
+
+ // Also works with objects.
+ assertEq(dn.of(Object(region)), expected);
+ }
+ }
+}
+
+{
+ let dn = new Intl.DisplayNames("en", {type: "region"});
+
+ // Performs ToString on the input and then validates the stringified result.
+ assertThrowsInstanceOf(() => dn.of(), RangeError);
+ assertThrowsInstanceOf(() => dn.of(null), RangeError);
+ assertThrowsInstanceOf(() => dn.of(Symbol()), TypeError);
+ assertThrowsInstanceOf(() => dn.of(0), RangeError);
+
+ // Throws an error if |code| can't be parsed as a `unicode_region_subtag` production.
+ assertThrowsInstanceOf(() => dn.of("CA-"), RangeError);
+ assertThrowsInstanceOf(() => dn.of("en-CA"), RangeError);
+}
+
+// Test fallback behaviour.
+{
+ let dn1 = new Intl.DisplayNames("en", {type: "region"});
+ let dn2 = new Intl.DisplayNames("en", {type: "region", fallback: "code"});
+ let dn3 = new Intl.DisplayNames("en", {type: "region", fallback: "none"});
+
+ assertEq(dn1.resolvedOptions().fallback, "code");
+ assertEq(dn2.resolvedOptions().fallback, "code");
+ assertEq(dn3.resolvedOptions().fallback, "none");
+
+ // "AA" is not a registered region code.
+ assertEq(dn1.of("AA"), "AA");
+ assertEq(dn2.of("AA"), "AA");
+ assertEq(dn3.of("AA"), undefined);
+
+ // The returned fallback is in canonical case.
+ assertEq(dn1.of("aa"), "AA");
+ assertEq(dn2.of("aa"), "AA");
+ assertEq(dn3.of("aa"), undefined);
+
+ // "998" is canonicalised to "XZ", but "XZ" has no localised names.
+ assertEq(new Intl.Locale("und-998").region, "XZ");
+
+ // Ensure we return the input and not the canonicalised input.
+ assertEq(dn1.of("998"), "998");
+ assertEq(dn2.of("998"), "998");
+ assertEq(dn3.of("998"), undefined);
+
+ // "XZ" should be consistent with "998".
+ assertEq(dn1.of("XZ"), "XZ");
+ assertEq(dn2.of("XZ"), "XZ");
+ assertEq(dn3.of("XZ"), undefined);
+}
+
+// Ensure language tag canonicalisation is performed.
+{
+ let dn = new Intl.DisplayNames("en", {type: "region", fallback: "none"});
+
+ assertEq(dn.of("RU"), "Russia");
+
+ // ICU's canonicalisation supports "SU" -> "RU".
+ assertEq(Intl.getCanonicalLocales("ru-SU")[0], "ru-RU");
+ assertEq(dn.of("SU"), "Russia");
+
+ // ICU's canonicalisation doesn't support "172" -> "RU".
+ assertEq(Intl.getCanonicalLocales("ru-172")[0], "ru-RU");
+ assertEq(dn.of("172"), "Russia");
+}
+
+// Test when case isn't canonical.
+{
+ let dn = new Intl.DisplayNames("en", {type: "region", fallback: "none"});
+
+ assertEq(dn.of("IT"), "Italy");
+ assertEq(dn.of("it"), "Italy");
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Intl/DisplayNames/script.js b/js/src/tests/non262/Intl/DisplayNames/script.js
new file mode 100644
index 0000000000..43b3ad5308
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/script.js
@@ -0,0 +1,134 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl'))
+
+const tests = {
+ "en": {
+ long: {
+ "Latn": "Latin",
+ "Hant": "Traditional Han",
+ "Hans": "Simplified Han",
+ "Cans": "Unified Canadian Aboriginal Syllabics",
+ },
+ short: {
+ "Hant": "Traditional",
+ "Hans": "Simplified",
+ "Cans": "UCAS",
+ },
+ narrow: {},
+ },
+ "de": {
+ long: {
+ "Latn": "Lateinisch",
+ "Hant": "Traditionelles Chinesisch",
+ "Hans": "Vereinfachtes Chinesisch",
+ },
+ short: {
+ "Hant": "Traditionell",
+ "Hans": "Vereinfacht",
+ },
+ narrow: {},
+ },
+ "fr": {
+ long: {
+ "Latn": "latin",
+ "Hant": "sinogrammes traditionnels",
+ "Hans": "sinogrammes simplifiés",
+ },
+ short: {
+ "Hant": "traditionnel",
+ "Hans": "simplifié",
+ },
+ narrow: {},
+ },
+ "zh": {
+ long: {
+ "Latn": "拉丁文",
+ "Hant": "繁体中文",
+ "Hans": "简体中文",
+ },
+ short: {
+ "Hant": "繁体",
+ "Hans": "简体",
+ },
+ narrow: {},
+ },
+ "ar": {
+ long: {
+ "Latn": "اللاتينية",
+ "Arab": "العربية",
+ "Hant": "الهان التقليدية",
+ "Hans": "الهان المبسطة",
+ },
+ short: {
+ "Hant": "التقليدية",
+ "Hans": "المبسطة",
+ },
+ narrow: {},
+ },
+};
+
+for (let [locale, localeTests] of Object.entries(tests)) {
+ for (let [style, styleTests] of Object.entries(localeTests)) {
+ let dn = new Intl.DisplayNames(locale, {type: "script", style});
+
+ let resolved = dn.resolvedOptions();
+ assertEq(resolved.locale, locale);
+ assertEq(resolved.style, style);
+ assertEq(resolved.type, "script");
+ assertEq(resolved.fallback, "code");
+
+ let inheritedTests = {...localeTests.long, ...localeTests.short, ...localeTests.narrow};
+ for (let [script, expected] of Object.entries({...inheritedTests, ...styleTests})) {
+ assertEq(dn.of(script), expected);
+
+ // Also works with objects.
+ assertEq(dn.of(Object(script)), expected);
+ }
+ }
+}
+
+{
+ let dn = new Intl.DisplayNames("en", {type: "script"});
+
+ // Performs ToString on the input and then validates the stringified result.
+ assertThrowsInstanceOf(() => dn.of(), RangeError);
+ assertThrowsInstanceOf(() => dn.of(Symbol()), TypeError);
+ assertThrowsInstanceOf(() => dn.of(0), RangeError);
+
+ // ToString(null) = "null", which passes `unicode_script_subtag`.
+ dn.of(null); // no error
+
+ // Throws an error if |code| can't be parsed as a `unicode_script_subtag` production.
+ assertThrowsInstanceOf(() => dn.of("latn-"), RangeError);
+ assertThrowsInstanceOf(() => dn.of("en-latn"), RangeError);
+}
+
+// Test fallback behaviour.
+{
+ let dn1 = new Intl.DisplayNames("en", {type: "script"});
+ let dn2 = new Intl.DisplayNames("en", {type: "script", fallback: "code"});
+ let dn3 = new Intl.DisplayNames("en", {type: "script", fallback: "none"});
+
+ assertEq(dn1.resolvedOptions().fallback, "code");
+ assertEq(dn2.resolvedOptions().fallback, "code");
+ assertEq(dn3.resolvedOptions().fallback, "none");
+
+ // "Aaaa" is not a registered script code.
+ assertEq(dn1.of("Aaaa"), "Aaaa");
+ assertEq(dn2.of("Aaaa"), "Aaaa");
+ assertEq(dn3.of("Aaaa"), undefined);
+
+ // The returned fallback is in canonical case.
+ assertEq(dn1.of("aaaa"), "Aaaa");
+ assertEq(dn2.of("aaaa"), "Aaaa");
+ assertEq(dn3.of("aaaa"), undefined);
+}
+
+// Test when case isn't canonical.
+{
+ let dn = new Intl.DisplayNames("en", {type: "script", fallback: "none"});
+
+ assertEq(dn.of("LATN"), "Latin");
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/non262/Intl/DisplayNames/shell.js b/js/src/tests/non262/Intl/DisplayNames/shell.js
new file mode 100644
index 0000000000..20326b0254
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/shell.js
@@ -0,0 +1,6 @@
+// Add |Intl.MozDisplayNames| to the Intl object.
+function addMozIntlDisplayNames(global) {
+ let obj = {};
+ global.addIntlExtras(obj);
+ global.Intl.DisplayNames = obj.DisplayNames;
+}
diff --git a/js/src/tests/non262/Intl/DisplayNames/weekday.js b/js/src/tests/non262/Intl/DisplayNames/weekday.js
new file mode 100644
index 0000000000..fd19f24bb1
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/weekday.js
@@ -0,0 +1,77 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl')||!this.hasOwnProperty('addIntlExtras'))
+
+addMozIntlDisplayNames(this);
+
+const tests = {
+ "en": {
+ long: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
+ // short: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
+ short: ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
+ narrow: ["M", "T", "W", "T", "F", "S", "S"],
+ },
+ "de": {
+ long: ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"],
+ // short: ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"],
+ short: ["Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa.", "So."],
+ narrow: ["M", "D", "M", "D", "F", "S", "S"],
+ },
+ "fr": {
+ long: ["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"],
+ // short: ["lun.", "mar.", "mer.", "jeu.", "ven.", "sam.", "dim."],
+ short: ["lu", "ma", "me", "je", "ve", "sa", "di"],
+ narrow: ["L", "M", "M", "J", "V", "S", "D"],
+ },
+ "zh": {
+ long: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
+ short: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
+ narrow: ["一", "二", "三", "四", "五", "六", "日"],
+ },
+};
+
+for (let [locale, localeTests] of Object.entries(tests)) {
+ let defaultCalendar = new Intl.DateTimeFormat(locale).resolvedOptions().calendar;
+
+ for (let [style, styleTests] of Object.entries(localeTests)) {
+ let dn = new Intl.DisplayNames(locale, {type: "weekday", style});
+
+ let resolved = dn.resolvedOptions();
+ assertEq(resolved.locale, locale);
+ assertEq(resolved.calendar, defaultCalendar);
+ assertEq(resolved.style, style);
+ assertEq(resolved.type, "weekday");
+ assertEq(resolved.fallback, "code");
+
+ for (let i = 0; i < 7; i++) {
+ assertEq(dn.of(i + 1), styleTests[i]);
+
+ // Also works with strings.
+ assertEq(dn.of(String(i + 1)), styleTests[i]);
+
+ // Also works with objects.
+ assertEq(dn.of(Object(i + 1)), styleTests[i]);
+ }
+ }
+}
+
+{
+ let dn = new Intl.DisplayNames("en", {type: "weekday"});
+
+ // Performs ToString on the input and then validates the stringified result.
+ assertThrowsInstanceOf(() => dn.of(), RangeError);
+ assertThrowsInstanceOf(() => dn.of(null), RangeError);
+ assertThrowsInstanceOf(() => dn.of(Symbol()), TypeError);
+
+ // Throws an error if |code| isn't an integer.
+ assertThrowsInstanceOf(() => dn.of(1.5), RangeError);
+ assertThrowsInstanceOf(() => dn.of(-Infinity), RangeError);
+ assertThrowsInstanceOf(() => dn.of(Infinity), RangeError);
+ assertThrowsInstanceOf(() => dn.of(NaN), RangeError);
+
+ // Throws an error if outside of [1, 7].
+ assertThrowsInstanceOf(() => dn.of(-1), RangeError);
+ assertThrowsInstanceOf(() => dn.of(0), RangeError);
+ assertThrowsInstanceOf(() => dn.of(8), RangeError);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);