tor-browser

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

constructor-options-region-valid.js (2261B)


      1 // Copyright 2018 André Bargull; 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 error cases for the options argument to the Locale
      8    constructor.
      9 info: |
     10    Intl.Locale( tag [, options] )
     11    10. If options is undefined, then
     12    11. Else
     13        a. Let options be ? ToObject(options).
     14    12. Set tag to ? ApplyOptionsToTag(tag, options).
     15 
     16    ApplyOptionsToTag( tag, options )
     17    ...
     18    7. Let region be ? GetOption(options, "region", "string", undefined, undefined).
     19    ...
     20    9. If tag matches neither the privateuse nor the grandfathered production, then
     21      ...
     22      d. If region is not undefined, then
     23        i. If tag does not contain a region production, then
     24          1. Set tag to the concatenation of the language production of tag, the substring corresponding to the "-" script production if present, "-", region, and the rest of tag.
     25        ii. Else,
     26          1. Set tag to tag with the substring corresponding to the region production replaced by the string region.
     27 
     28 features: [Intl.Locale]
     29 ---*/
     30 
     31 const validRegionOptions = [
     32  [undefined, undefined],
     33  ['FR', 'en-FR'],
     34  ['554', 'en-NZ'],
     35  [554, 'en-NZ'],
     36 ];
     37 for (const [region, expected] of validRegionOptions) {
     38  let options = { region };
     39  let expect = expected || 'en';
     40 
     41  assert.sameValue(
     42    new Intl.Locale('en', options).toString(),
     43    expect,
     44    `new Intl.Locale('en', {region: "${region}"}).toString() returns "${expect}"`
     45  );
     46 
     47  expect = expected || 'en-US';
     48  assert.sameValue(
     49    new Intl.Locale('en-US', options).toString(),
     50    expect,
     51    `new Intl.Locale('en-US', {region: "${region}"}).toString() returns "${expect}"`
     52  );
     53 
     54  expect = (expected || 'en') + '-u-ca-gregory';
     55  assert.sameValue(
     56    new Intl.Locale('en-u-ca-gregory', options).toString(),
     57    expect,
     58    `new Intl.Locale('en-u-ca-gregory', {region: "${region}"}).toString() returns "${expect}"`
     59  );
     60 
     61  expect = (expected || 'en-US') + '-u-ca-gregory';
     62  assert.sameValue(
     63    new Intl.Locale('en-US-u-ca-gregory', options).toString(),
     64    expect,
     65    `new Intl.Locale('en-US-u-ca-gregory', {region: "${region}"}).toString() returns "${expect}"`
     66  );
     67 }
     68 
     69 reportCompare(0, 0);