tor-browser

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

unit-well-formed.js (7525B)


      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 const allUnits = [
     54    "acceleration-g-force",
     55    "acceleration-meter-per-square-second",
     56    "angle-arc-minute",
     57    "angle-arc-second",
     58    "angle-degree",
     59    "angle-radian",
     60    "angle-revolution",
     61    "angle-steradian",
     62    "area-acre",
     63    "area-bu-jp",
     64    "area-cho",
     65    "area-dunam",
     66    "area-hectare",
     67    "area-se-jp",
     68    "area-square-centimeter",
     69    "area-square-foot",
     70    "area-square-inch",
     71    "area-square-kilometer",
     72    "area-square-meter",
     73    "area-square-mile",
     74    "area-square-yard",
     75    "concentr-item",
     76    "concentr-karat",
     77    "concentr-katal",
     78    "concentr-milligram-ofglucose-per-deciliter",
     79    "concentr-millimole-per-liter",
     80    "concentr-mole",
     81    "concentr-ofglucose",
     82    "concentr-part",
     83    "concentr-part-per-1e6",
     84    "concentr-part-per-1e9",
     85    "concentr-percent",
     86    "concentr-permille",
     87    "concentr-permyriad",
     88    "consumption-liter-per-100-kilometer",
     89    "consumption-liter-per-kilometer",
     90    "consumption-mile-per-gallon",
     91    "consumption-mile-per-gallon-imperial",
     92    "digital-bit",
     93    "digital-byte",
     94    "digital-gigabit",
     95    "digital-gigabyte",
     96    "digital-kilobit",
     97    "digital-kilobyte",
     98    "digital-megabit",
     99    "digital-megabyte",
    100    "digital-petabyte",
    101    "digital-terabit",
    102    "digital-terabyte",
    103    "duration-century",
    104    "duration-day",
    105    "duration-day-person",
    106    "duration-decade",
    107    "duration-fortnight",
    108    "duration-hour",
    109    "duration-microsecond",
    110    "duration-millisecond",
    111    "duration-minute",
    112    "duration-month",
    113    "duration-month-person",
    114    "duration-nanosecond",
    115    "duration-night",
    116    "duration-quarter",
    117    "duration-second",
    118    "duration-week",
    119    "duration-week-person",
    120    "duration-year",
    121    "duration-year-person",
    122    "electric-ampere",
    123    "electric-coulomb",
    124    "electric-farad",
    125    "electric-henry",
    126    "electric-milliampere",
    127    "electric-ohm",
    128    "electric-siemens",
    129    "electric-volt",
    130    "energy-becquerel",
    131    "energy-british-thermal-unit",
    132    "energy-british-thermal-unit-it",
    133    "energy-calorie",
    134    "energy-calorie-it",
    135    "energy-electronvolt",
    136    "energy-foodcalorie",
    137    "energy-gray",
    138    "energy-joule",
    139    "energy-kilocalorie",
    140    "energy-kilojoule",
    141    "energy-kilowatt-hour",
    142    "energy-sievert",
    143    "energy-therm-us",
    144    "force-kilogram-force",
    145    "force-kilowatt-hour-per-100-kilometer",
    146    "force-newton",
    147    "force-pound-force",
    148    "frequency-gigahertz",
    149    "frequency-hertz",
    150    "frequency-kilohertz",
    151    "frequency-megahertz",
    152    "graphics-dot",
    153    "graphics-dot-per-centimeter",
    154    "graphics-dot-per-inch",
    155    "graphics-em",
    156    "graphics-megapixel",
    157    "graphics-pixel",
    158    "graphics-pixel-per-centimeter",
    159    "graphics-pixel-per-inch",
    160    "length-astronomical-unit",
    161    "length-centimeter",
    162    "length-chain",
    163    "length-decimeter",
    164    "length-earth-radius",
    165    "length-fathom",
    166    "length-foot",
    167    "length-furlong",
    168    "length-inch",
    169    "length-jo-jp",
    170    "length-ken",
    171    "length-kilometer",
    172    "length-light-year",
    173    "length-meter",
    174    "length-micrometer",
    175    "length-mile",
    176    "length-mile-scandinavian",
    177    "length-millimeter",
    178    "length-nanometer",
    179    "length-nautical-mile",
    180    "length-parsec",
    181    "length-picometer",
    182    "length-point",
    183    "length-ri-jp",
    184    "length-rin",
    185    "length-rod",
    186    "length-shaku-cloth",
    187    "length-shaku-length",
    188    "length-solar-radius",
    189    "length-sun",
    190    "length-yard",
    191    "light-candela",
    192    "light-lumen",
    193    "light-lux",
    194    "light-solar-luminosity",
    195    "magnetic-tesla",
    196    "magnetic-weber",
    197    "mass-carat",
    198    "mass-dalton",
    199    "mass-earth-mass",
    200    "mass-fun",
    201    "mass-grain",
    202    "mass-gram",
    203    "mass-kilogram",
    204    "mass-microgram",
    205    "mass-milligram",
    206    "mass-ounce",
    207    "mass-ounce-troy",
    208    "mass-pound",
    209    "mass-slug",
    210    "mass-solar-mass",
    211    "mass-stone",
    212    "mass-ton",
    213    "mass-tonne",
    214    "power-gigawatt",
    215    "power-horsepower",
    216    "power-kilowatt",
    217    "power-megawatt",
    218    "power-milliwatt",
    219    "power-watt",
    220    "pressure-atmosphere",
    221    "pressure-bar",
    222    "pressure-gasoline-energy-density",
    223    "pressure-hectopascal",
    224    "pressure-inch-ofhg",
    225    "pressure-kilopascal",
    226    "pressure-megapascal",
    227    "pressure-millibar",
    228    "pressure-millimeter-ofhg",
    229    "pressure-ofhg",
    230    "pressure-pascal",
    231    "pressure-pound-force-per-square-inch",
    232    "speed-beaufort",
    233    "speed-kilometer-per-hour",
    234    "speed-knot",
    235    "speed-light-speed",
    236    "speed-meter-per-second",
    237    "speed-mile-per-hour",
    238    "temperature-celsius",
    239    "temperature-fahrenheit",
    240    "temperature-generic",
    241    "temperature-kelvin",
    242    "temperature-rankine",
    243    "torque-newton-meter",
    244    "torque-pound-force-foot",
    245    "volume-acre-foot",
    246    "volume-barrel",
    247    "volume-bushel",
    248    "volume-centiliter",
    249    "volume-cubic-centimeter",
    250    "volume-cubic-foot",
    251    "volume-cubic-inch",
    252    "volume-cubic-kilometer",
    253    "volume-cubic-meter",
    254    "volume-cubic-mile",
    255    "volume-cubic-yard",
    256    "volume-cup",
    257    "volume-cup-imperial",
    258    "volume-cup-jp",
    259    "volume-cup-metric",
    260    "volume-deciliter",
    261    "volume-dessert-spoon",
    262    "volume-dessert-spoon-imperial",
    263    "volume-dram",
    264    "volume-drop",
    265    "volume-fluid-ounce",
    266    "volume-fluid-ounce-imperial",
    267    "volume-fluid-ounce-metric",
    268    "volume-gallon",
    269    "volume-gallon-imperial",
    270    "volume-hectoliter",
    271    "volume-jigger",
    272    "volume-koku",
    273    "volume-kosaji",
    274    "volume-liter",
    275    "volume-megaliter",
    276    "volume-milliliter",
    277    "volume-osaji",
    278    "volume-pinch",
    279    "volume-pint",
    280    "volume-pint-imperial",
    281    "volume-pint-metric",
    282    "volume-quart",
    283    "volume-quart-imperial",
    284    "volume-sai",
    285    "volume-shaku",
    286    "volume-tablespoon",
    287    "volume-teaspoon",
    288    "volume-to-jp"
    289 ];
    290 
    291 // Test only sanctioned unit identifiers are allowed.
    292 
    293 for (const typeAndUnit of allUnits) {
    294    const [_, type, unit] = typeAndUnit.match(/(\w+)-(.+)/);
    295 
    296    let allowed;
    297    if (unit.includes("-per-")) {
    298        const [numerator, denominator] = unit.split("-per-");
    299        allowed = sanctionedSimpleUnitIdentifiers.includes(numerator) &&
    300                  sanctionedSimpleUnitIdentifiers.includes(denominator);
    301    } else {
    302        allowed = sanctionedSimpleUnitIdentifiers.includes(unit);
    303    }
    304 
    305    if (allowed) {
    306        const nf = new Intl.NumberFormat("en", {style: "unit", unit});
    307        assertEq(nf.format(1), nf.formatToParts(1).map(p => p.value).join(""));
    308    } else {
    309        assertThrowsInstanceOf(() => new Intl.NumberFormat("en", {style: "unit", unit}),
    310                               RangeError, `Missing error for "${typeAndUnit}"`);
    311    }
    312 }
    313 
    314 if (typeof reportCompare === "function")
    315    reportCompare(true, true);