tor-browser

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

report-warning-for-deprecated-islamic.js (1883B)


      1 // |reftest| skip-if(!this.hasOwnProperty("Intl")||!xulRuntime.shell)
      2 
      3 const locales = [
      4  "en", "ar", "ar-SA", "ar-EG",
      5 ];
      6 
      7 const deprecated = [
      8  "islamic",
      9 ];
     10 
     11 const supportedCalendars = Intl.supportedValuesOf("calendar");
     12 
     13 function test(calendar, locale, options = undefined) {
     14  // Enable warning reporter.
     15  enableLastWarning();
     16 
     17  // Create new DateTimeFormat.
     18  let dtf = new Intl.DateTimeFormat(locale, options);
     19 
     20  // Options are lazily resolved...
     21  let resolved = dtf.resolvedOptions();
     22 
     23  // Inspect last warning.
     24  if (deprecated.includes(calendar)) {
     25    let warning = getLastWarning();
     26    assertEq(warning !== null, true, `missing warning for ${locale}`);
     27    assertEq(
     28      warning.message.includes(calendar),
     29      true,
     30      `warning "${warning}" doesn't include calendar "${calendar}"`
     31    );
     32 
     33    assertEq(
     34      resolved.calendar,
     35      "islamic-tbla",
     36      `bad resolved fallback calendar for ${locale}`
     37    );
     38  } else {
     39    let warning = getLastWarning();
     40    assertEq(warning === null, true, `unexpected warning for ${locale}`);
     41 
     42    assertEq(
     43      resolved.calendar,
     44      calendar,
     45      `bad resolved calendar for ${locale}`
     46    );
     47  }
     48 
     49  // Disable warning reporter.
     50  disableLastWarning();
     51 }
     52 
     53 for (let calendar of [...deprecated, ...supportedCalendars]) {
     54  if (deprecated.includes(calendar)) {
     55    assertEq(
     56      supportedCalendars.includes(calendar),
     57      false,
     58      `${calendar} is deprecated`
     59    );
     60  }
     61 
     62  for (let locale of locales) {
     63    // Test as option.
     64    test(calendar, locale, {calendar});
     65 
     66    // Test as Unicode local extension.
     67    test(calendar, locale + "-u-ca-" + calendar);
     68 
     69    // Also test with non-canonical case.
     70    test(calendar, locale, {calendar: calendar.toUpperCase()});
     71    test(calendar, locale + "-u-ca-" + calendar.toUpperCase());
     72  }
     73 }
     74 
     75 if (typeof reportCompare === "function")
     76  reportCompare(true, true);