tor-browser

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

test-option-useGrouping.js (1450B)


      1 // Copyright 2012 Mozilla Corporation. All rights reserved.
      2 // Copyright 2022 Apple Inc. All rights reserved.
      3 // Copyright 2022 Igalia, S.L. All rights reserved.
      4 // This code is governed by the BSD license found in the LICENSE file.
      5 
      6 /*---
      7 es5id: 11.1.1_34
      8 description: Tests that the option useGrouping is processed correctly.
      9 info: |
     10  The "Intl.NumberFormat v3" proposal contradicts the behavior required by the
     11  latest revision of ECMA402.
     12 author: Norbert Lindenberg
     13 features: [Intl.NumberFormat-v3]
     14 ---*/
     15 
     16 function resolveUseGrouping(option) {
     17  return new Intl.NumberFormat(undefined, { useGrouping: option }).resolvedOptions().useGrouping;
     18 }
     19 
     20 for (let string of ["min2", "auto", "always"]) {
     21  assert.sameValue(resolveUseGrouping(string), string);
     22 }
     23 
     24 assert.sameValue(resolveUseGrouping(true), "always");
     25 assert.sameValue(resolveUseGrouping(false), false);
     26 assert.sameValue(resolveUseGrouping(undefined), "auto");
     27 assert.sameValue(resolveUseGrouping("true"), "auto");
     28 assert.sameValue(resolveUseGrouping("false"), "auto");
     29 
     30 for (let falsy of [0, null, ""]) {
     31  assert.sameValue(resolveUseGrouping(falsy), false);
     32 }
     33 
     34 for (let invalidOptions of [42, "MIN2", {} , "True",  "TRUE" , "FALSE" , "False" , "Undefined" , "undefined"]) {
     35  assert.throws(RangeError, function () {
     36    return new Intl.NumberFormat(undefined, { useGrouping: invalidOptions });
     37  }, "Throws RangeError when useGrouping value is not supported");
     38 }
     39 
     40 
     41 
     42 reportCompare(0, 0);