tor-browser

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

constructor-compactDisplay-no-compact.js (1426B)


      1 // Copyright 2019 Igalia, S.L. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-initializenumberformat
      6 description: Checks handling of the compactDisplay option to the NumberFormat constructor.
      7 info: |
      8    InitializeNumberFormat ( numberFormat, locales, options )
      9 
     10    19. Let compactDisplay be ? GetOption(options, "compactDisplay", "string", « "short", "long" », "short").
     11    20. If notation is "compact", then
     12        a. Set numberFormat.[[CompactDisplay]] to compactDisplay.
     13 
     14 includes: [compareArray.js]
     15 features: [Intl.NumberFormat-unified]
     16 ---*/
     17 
     18 const values = [
     19  [undefined, "short"],
     20  ["short"],
     21  ["long"],
     22 ];
     23 
     24 const notations = [
     25  undefined,
     26  "standard",
     27  "scientific",
     28  "engineering",
     29 ];
     30 
     31 for (const notation of notations) {
     32  for (const [value, expected = value] of values) {
     33    const callOrder = [];
     34    const nf = new Intl.NumberFormat([], {
     35      get notation() {
     36        callOrder.push("notation");
     37        return notation;
     38      },
     39      get compactDisplay() {
     40        callOrder.push("compactDisplay");
     41        return value;
     42      }
     43    });
     44    const resolvedOptions = nf.resolvedOptions();
     45    assert.sameValue("compactDisplay" in resolvedOptions, false);
     46    assert.sameValue(resolvedOptions.compactDisplay, undefined);
     47 
     48    assert.compareArray(callOrder, [
     49      "notation",
     50      "compactDisplay",
     51    ]);
     52  }
     53 }
     54 
     55 reportCompare(0, 0);