tor-browser

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

trailing-zero-display.js (2824B)


      1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
      2 
      3 // "stripIfInteger" with fractional digits.
      4 {
      5  let nf1 = new Intl.NumberFormat("en", {
      6    minimumFractionDigits: 2,
      7  });
      8 
      9  let nf2 = new Intl.NumberFormat("en", {
     10    minimumFractionDigits: 2,
     11    trailingZeroDisplay: "auto",
     12  });
     13 
     14  let nf3 = new Intl.NumberFormat("en", {
     15    minimumFractionDigits: 2,
     16    trailingZeroDisplay: "stripIfInteger",
     17  });
     18 
     19  assertEq(nf1.resolvedOptions().trailingZeroDisplay, "auto");
     20  assertEq(nf2.resolvedOptions().trailingZeroDisplay, "auto");
     21  assertEq(nf3.resolvedOptions().trailingZeroDisplay, "stripIfInteger");
     22 
     23  assertEq(nf1.format(123), "123.00");
     24  assertEq(nf2.format(123), "123.00");
     25  assertEq(nf3.format(123), "123");
     26 }
     27 
     28 // "stripIfInteger" with significand digits.
     29 {
     30  let nf1 = new Intl.NumberFormat("en", {
     31    minimumSignificantDigits: 2,
     32  });
     33 
     34  let nf2 = new Intl.NumberFormat("en", {
     35    minimumSignificantDigits: 2,
     36    trailingZeroDisplay: "auto",
     37  });
     38 
     39  let nf3 = new Intl.NumberFormat("en", {
     40    minimumSignificantDigits: 2,
     41    trailingZeroDisplay: "stripIfInteger",
     42  });
     43 
     44  assertEq(nf1.resolvedOptions().trailingZeroDisplay, "auto");
     45  assertEq(nf2.resolvedOptions().trailingZeroDisplay, "auto");
     46  assertEq(nf3.resolvedOptions().trailingZeroDisplay, "stripIfInteger");
     47 
     48  assertEq(nf1.format(1), "1.0");
     49  assertEq(nf2.format(1), "1.0");
     50  assertEq(nf3.format(1), "1");
     51 }
     52 
     53 // "stripIfInteger" with rounding increment.
     54 {
     55  let nf1 = new Intl.NumberFormat("en", {
     56    minimumFractionDigits: 2,
     57    maximumFractionDigits: 2,
     58    roundingIncrement: 5,
     59  });
     60  let nf2 = new Intl.NumberFormat("en", {
     61    minimumFractionDigits: 2,
     62    maximumFractionDigits: 2,
     63    roundingIncrement: 5,
     64    trailingZeroDisplay: "auto",
     65  });
     66  let nf3 = new Intl.NumberFormat("en", {
     67    minimumFractionDigits: 2,
     68    maximumFractionDigits: 2,
     69    roundingIncrement: 5,
     70    trailingZeroDisplay: "stripIfInteger",
     71  });
     72 
     73  assertEq(nf1.resolvedOptions().trailingZeroDisplay, "auto");
     74  assertEq(nf2.resolvedOptions().trailingZeroDisplay, "auto");
     75  assertEq(nf3.resolvedOptions().trailingZeroDisplay, "stripIfInteger");
     76 
     77  // NB: Tests 1.975 twice b/c of <https://unicode-org.atlassian.net/browse/ICU-21674>.
     78 
     79  assertEq(nf1.format(1.975), "2.00");
     80  assertEq(nf1.format(1.97), "1.95");
     81  assertEq(nf1.format(1.975), "2.00");
     82 
     83  assertEq(nf2.format(1.975), "2.00");
     84  assertEq(nf2.format(1.97), "1.95");
     85  assertEq(nf2.format(1.975), "2.00");
     86 
     87  assertEq(nf3.format(1.975), "2");
     88  assertEq(nf3.format(1.97), "1.95");
     89  assertEq(nf3.format(1.975), "2");
     90 }
     91 
     92 // Invalid values.
     93 for (let trailingZeroDisplay of ["", "true", true, "none", "yes", "no"]){
     94  assertThrowsInstanceOf(() => new Intl.NumberFormat("en", {trailingZeroDisplay}), RangeError);
     95 }
     96 
     97 if (typeof reportCompare === "function")
     98  reportCompare(true, true);