tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

implied-script-has-consistent-output.js (2347B)


      1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
      2 
      3 if (typeof getAvailableLocalesOf === "undefined") {
      4  var getAvailableLocalesOf = SpecialPowers.Cu.getJSTestingFunctions().getAvailableLocalesOf;
      5 }
      6 
      7 // Retrieve all available locales of Intl.DateTimeFormat.
      8 const available = getAvailableLocalesOf("DateTimeFormat");
      9 
     10 const options = [
     11  // Include "hour" to catch hour cycle differences.
     12  //
     13  // For example "ff-Latn-GH" (Fulah as spoken in Ghana) uses a 12-hour clock,
     14  // whereas "ff" (Fulah) uses a 24-hour clock. When the user creates the
     15  // formatter for "ff-GH", it should use the same formatter data as "ff-Latn-GH"
     16  // and it shouldn't fallback to "ff".
     17  {hour: "2-digit", minute: "2-digit", timeZone: "UTC"},
     18 
     19  // Include "timeZoneName" to catch script differences, e.g traditional or
     20  // simplified Chinese characters.
     21  {timeZoneName: "long", timeZone: "America/Los_Angeles"},
     22 ];
     23 
     24 // Pick a date after 12 pm to catch any hour cycle differences.
     25 const date = Date.UTC(2021, 6-1, 7, 15, 0);
     26 
     27 available.map(x => {
     28  return new Intl.Locale(x);
     29 }).filter(loc => {
     30  // Find all locales which have both a script and a region subtag.
     31  return loc.script && loc.region;
     32 }).filter(loc => {
     33  // Skip "ku-Latn-IQ" because "ku-Arab" isn't exported from CLDR to ICU and the
     34  // implied script of "ku-IQ" is "ku-Arab-IQ".
     35  // This can result in hour cycle differences, see also
     36  // <https://unicode-org.atlassian.net/browse/CLDR-19048>.
     37  if (loc.language === "ku" && loc.script === "Latn" && loc.region === "IQ") {
     38    return false;
     39  }
     40  return true;
     41 }).forEach(loc => {
     42  // Remove the script subtag from the locale.
     43  let noScript = new Intl.Locale(`${loc.language}-${loc.region}`);
     44 
     45  // Add the likely script subtag.
     46  let maximized = noScript.maximize();
     47 
     48  for (let opt of options) {
     49    // Formatter for the locale without a script subtag.
     50    let df1 = new Intl.DateTimeFormat(noScript, opt);
     51 
     52    // Formatter for the locale with the likely script subtag added.
     53    let df2 = new Intl.DateTimeFormat(maximized, opt);
     54 
     55    // The output for the locale without a script subtag should match the output
     56    // with the likely script subtag added.
     57    assertEq(df1.format(date), df2.format(date), `Mismatch for locale "${noScript}" (${maximized})`);
     58  }
     59 });
     60 
     61 if (typeof reportCompare === "function")
     62  reportCompare(0, 0, "ok");