summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/DateTimeFormat/implied-script-has-consistent-output.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/non262/Intl/DateTimeFormat/implied-script-has-consistent-output.js')
-rw-r--r--js/src/tests/non262/Intl/DateTimeFormat/implied-script-has-consistent-output.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/DateTimeFormat/implied-script-has-consistent-output.js b/js/src/tests/non262/Intl/DateTimeFormat/implied-script-has-consistent-output.js
new file mode 100644
index 0000000000..6c0b4d2f59
--- /dev/null
+++ b/js/src/tests/non262/Intl/DateTimeFormat/implied-script-has-consistent-output.js
@@ -0,0 +1,59 @@
+// |reftest| skip-if(!this.hasOwnProperty("Intl"))
+
+if (typeof getAvailableLocalesOf === "undefined") {
+ var getAvailableLocalesOf = SpecialPowers.Cu.getJSTestingFunctions().getAvailableLocalesOf;
+}
+
+// Retrieve all available locales of Intl.DateTimeFormat.
+const available = getAvailableLocalesOf("DateTimeFormat");
+
+const options = [
+ // Include "hour" to catch hour cycle differences.
+ //
+ // For example "ff-Latn-GH" (Fulah as spoken in Ghana) uses a 12-hour clock,
+ // whereas "ff" (Fulah) uses a 24-hour clock. When the user creates the
+ // formatter for "ff-GH", it should use the same formatter data as "ff-Latn-GH"
+ // and it shouldn't fallback to "ff".
+ {hour: "2-digit", minute: "2-digit", timeZone: "UTC"},
+
+ // Include "timeZoneName" to catch script differences, e.g traditional or
+ // simplified Chinese characters.
+ {timeZoneName: "long", timeZone: "America/Los_Angeles"},
+];
+
+// Pick a date after 12 pm to catch any hour cycle differences.
+const date = Date.UTC(2021, 6-1, 7, 15, 0);
+
+available.map(x => {
+ return new Intl.Locale(x);
+}).filter(loc => {
+ // Find all locales which have both a script and a region subtag.
+ return loc.script && loc.region;
+}).filter(loc => {
+ // Skip "sd-Deva-IN" and Fulah because of <https://unicode-org.atlassian.net/browse/ICU-21974>.
+ return !((loc.language === "sd" && loc.script === "Deva" && loc.region === "IN") ||
+ (loc.language === "ff" && (loc.script === "Adlm" || loc.script === "Latn") &&
+ (loc.region === "GH" || loc.region === "GM" || loc.region === "LR" || loc.region === "SL"))
+ );
+}).forEach(loc => {
+ // Remove the script subtag from the locale.
+ let noScript = new Intl.Locale(`${loc.language}-${loc.region}`);
+
+ // Add the likely script subtag.
+ let maximized = noScript.maximize();
+
+ for (let opt of options) {
+ // Formatter for the locale without a script subtag.
+ let df1 = new Intl.DateTimeFormat(noScript, opt);
+
+ // Formatter for the locale with the likely script subtag added.
+ let df2 = new Intl.DateTimeFormat(maximized, opt);
+
+ // The output for the locale without a script subtag should match the output
+ // with the likely script subtag added.
+ assertEq(df1.format(date), df2.format(date), `Mismatch for locale "${noScript}" (${maximized})`);
+ }
+});
+
+if (typeof reportCompare === "function")
+ reportCompare(0, 0, "ok");