tor-browser

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

units-accepted-by-NumberFormat.js (1527B)


      1 // Copyright (C) 2021 André Bargull. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-intl.supportedvaluesof
      6 description: >
      7  The returned "unit" values can be used with NumberFormat.
      8 info: |
      9  Intl.supportedValuesOf ( key )
     10 
     11  1. Let key be ? ToString(key).
     12  ...
     13  7. Else if key is "unit", then
     14    a. Let list be ! AvailableUnits( ).
     15  ...
     16  9. Return ! CreateArrayFromList( list ).
     17 
     18  AvailableUnits ( )
     19    The AvailableUnits abstract operation returns a List, ordered as if an Array
     20    of the same values had been sorted using %Array.prototype.sort% using
     21    undefined as comparefn, that contains the unique values of simple unit
     22    identifiers listed in every row of Table 1, except the header row.
     23 includes: [testIntl.js]
     24 locale: [en]
     25 features: [Intl-enumeration, Array.prototype.includes]
     26 ---*/
     27 
     28 const units = Intl.supportedValuesOf("unit");
     29 
     30 for (let unit of units) {
     31  let obj = new Intl.NumberFormat("en", {style: "unit", unit});
     32  assert.sameValue(obj.resolvedOptions().unit, unit,
     33                   `${unit} is supported by NumberFormat`);
     34 }
     35 
     36 for (let unit of allSimpleSanctionedUnits()) {
     37  let obj = new Intl.NumberFormat("en", {style: "unit", unit});
     38  if (obj.resolvedOptions().unit === unit) {
     39    assert(units.includes(unit),
     40           `${unit} supported but not returned by supportedValuesOf`);
     41  } else {
     42    assert(!units.includes(unit),
     43           `${unit} not supported but returned by supportedValuesOf`);
     44  }
     45 }
     46 
     47 reportCompare(0, 0);