tor-browser

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

unit-formatToParts-has-unit-field.js (2035B)


      1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
      2 
      3 // Generated by make_intl_data.py. DO NOT EDIT.
      4 
      5 const sanctionedSimpleUnitIdentifiers = [
      6  "acre",
      7  "bit",
      8  "byte",
      9  "celsius",
     10  "centimeter",
     11  "day",
     12  "degree",
     13  "fahrenheit",
     14  "fluid-ounce",
     15  "foot",
     16  "gallon",
     17  "gigabit",
     18  "gigabyte",
     19  "gram",
     20  "hectare",
     21  "hour",
     22  "inch",
     23  "kilobit",
     24  "kilobyte",
     25  "kilogram",
     26  "kilometer",
     27  "liter",
     28  "megabit",
     29  "megabyte",
     30  "meter",
     31  "microsecond",
     32  "mile",
     33  "mile-scandinavian",
     34  "milliliter",
     35  "millimeter",
     36  "millisecond",
     37  "minute",
     38  "month",
     39  "nanosecond",
     40  "ounce",
     41  "percent",
     42  "petabyte",
     43  "pound",
     44  "second",
     45  "stone",
     46  "terabit",
     47  "terabyte",
     48  "week",
     49  "yard",
     50  "year"
     51 ];
     52 
     53 // Test only English and Chinese to keep the overall runtime reasonable.
     54 //
     55 // Chinese is included because it contains more than one "unit" element for
     56 // certain unit combinations.
     57 const locales = ["en", "zh"];
     58 
     59 // Plural rules for English only differentiate between "one" and "other". Plural
     60 // rules for Chinese only use "other". That means we only need to test two values
     61 // per unit.
     62 const values = [0, 1];
     63 
     64 // Ensure unit formatters contain at least one "unit" element.
     65 
     66 for (const locale of locales) {
     67  for (const unit of sanctionedSimpleUnitIdentifiers) {
     68    const nf = new Intl.NumberFormat(locale, {style: "unit", unit});
     69 
     70    for (const value of values) {
     71      assertEq(nf.formatToParts(value).some(e => e.type === "unit"), true,
     72               `locale=${locale}, unit=${unit}`);
     73    }
     74  }
     75 
     76  for (const numerator of sanctionedSimpleUnitIdentifiers) {
     77    for (const denominator of sanctionedSimpleUnitIdentifiers) {
     78      const unit = `${numerator}-per-${denominator}`;
     79      const nf = new Intl.NumberFormat(locale, {style: "unit", unit});
     80 
     81      for (const value of values) {
     82        assertEq(nf.formatToParts(value).some(e => e.type === "unit"), true,
     83                 `locale=${locale}, unit=${unit}`);
     84      }
     85    }
     86  }
     87 }
     88 
     89 if (typeof reportCompare === "function")
     90  reportCompare(true, true);