tor-browser

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

formatRangeToParts-approximately-sign-unit.js (1372B)


      1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
      2 
      3 if (typeof getAvailableLocalesOf === "undefined") {
      4  var getAvailableLocalesOf = SpecialPowers.Cu.getJSTestingFunctions().getAvailableLocalesOf;
      5 }
      6 
      7 const numbers = [
      8  0, 1, 2, 5, 10, 100, 1000, 10_000, 100_000, 1_000_000,
      9  0.1, 0.2, 0.5, 1.5,
     10  -0, -1, -2, -5,
     11  Infinity, -Infinity,
     12 ];
     13 
     14 const options = {style: "unit", unit: "meter"};
     15 
     16 // List of known approximately sign in CLDR 46.
     17 const approximatelySigns = [
     18  "-", "~", "∼", "≈", "≃", "ca.", "約", "dáàṣì", "dáàshì",
     19 ];
     20 
     21 // Iterate over all locales and ensure we find exactly one approximately sign.
     22 for (let locale of getAvailableLocalesOf("NumberFormat").sort()) {
     23  let nf = new Intl.NumberFormat(locale, options);
     24  for (let number of numbers) {
     25    let parts = nf.formatRangeToParts(number, number);
     26    let approx = parts.filter(part => part.type === "approximatelySign");
     27 
     28    // Known failure case.
     29    // - https://github.com/tc39/proposal-intl-numberformat-v3/issues/64
     30    // - https://unicode-org.atlassian.net/browse/CLDR-14918
     31    if (approx.length === 0 && new Intl.Locale(locale).language === "ar") {
     32      continue;
     33    }
     34 
     35    assertEq(approx.length, 1);
     36    assertEq(approximatelySigns.some(approxSign => approx[0].value.includes(approxSign)), true);
     37  }
     38 }
     39 
     40 if (typeof reportCompare === "function")
     41  reportCompare(true, true);