tor-browser

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

constructor-options-numeric-valid.js (2216B)


      1 // Copyright 2018 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-intl.locale
      6 description: >
      7    Checks valid cases for the options argument to the Locale constructor.
      8 info: |
      9    Intl.Locale( tag [, options] )
     10 
     11    ...
     12    24. Let kn be ? GetOption(options, "numeric", "boolean", undefined, undefined).
     13    25. If kn is not undefined, set kn to ! ToString(kn).
     14    ...
     15    30. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys).
     16    ...
     17 
     18    ApplyUnicodeExtensionToTag( tag, options, relevantExtensionKeys )
     19 
     20    ...
     21    8. Let locale be the String value that is tag with all Unicode locale extension sequences removed.
     22    9. Let newExtension be ! CanonicalizeUnicodeExtension(attributes, keywords).
     23    10. If newExtension is not the empty String, then
     24        a. Let locale be ! InsertUnicodeExtension(locale, newExtension).
     25    ...
     26 
     27    CanonicalizeUnicodeExtension( attributes, keywords )
     28    ...
     29    4. Repeat for each element entry of keywords in List order,
     30        a. Let keyword be entry.[[Key]].
     31        b. If entry.[[Value]] is not the empty String, then
     32            i. Let keyword be the string-concatenation of keyword, "-", and entry.[[Value]].
     33        c. Append keyword to fullKeywords.
     34    ...
     35 features: [Intl.Locale]
     36 ---*/
     37 
     38 const validNumericOptions = [
     39  [false, false],
     40  [true, true],
     41  [null, false],
     42  [0, false],
     43  [0.5, true],
     44  ["true", true],
     45  ["false", true],
     46  [{ valueOf() { return false; } }, true],
     47 ];
     48 for (const [numeric, expected] of validNumericOptions) {
     49  let expect = expected ? "en-u-kn" : "en-u-kn-false";
     50 
     51  assert.sameValue(
     52    new Intl.Locale('en', {numeric}).toString(),
     53    expect,
     54    `new Intl.Locale("en", {numeric: ${numeric}}).toString() returns "${expected}"`
     55  );
     56 
     57  assert.sameValue(
     58    new Intl.Locale('en-u-kn-true', {numeric}).toString(),
     59    expect,
     60    `new Intl.Locale("en-u-kn-true", {numeric: ${numeric}}).toString() returns "${expected}"`
     61  );
     62 
     63  assert.sameValue(
     64    new Intl.Locale('en-u-kf-lower', {numeric}).numeric,
     65    expected,
     66    `new Intl.Locale("en-u-kf-lower", {numeric: ${numeric}}).numeric equals "${expected}"`
     67  );
     68 }
     69 
     70 reportCompare(0, 0);