tor-browser

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

constructor-options-collation-valid.js (2147B)


      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    17. Let collation be ? GetOption(options, "collation", "string", undefined, undefined).
     13    ...
     14    19. Set opt.[[co]] to collation.
     15    ...
     16    30. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys).
     17    ...
     18 
     19    ApplyUnicodeExtensionToTag( tag, options, relevantExtensionKeys )
     20 
     21    ...
     22    8. Let locale be the String value that is tag with all Unicode locale extension sequences removed.
     23    9. Let newExtension be ! CanonicalizeUnicodeExtension(attributes, keywords).
     24    10. If newExtension is not the empty String, then
     25        a. Let locale be ! InsertUnicodeExtension(locale, newExtension).
     26    ...
     27 
     28    CanonicalizeUnicodeExtension( attributes, keywords )
     29    ...
     30    4. Repeat for each element entry of keywords in List order,
     31        a. Let keyword be entry.[[Key]].
     32        b. If entry.[[Value]] is not the empty String, then
     33            i. Let keyword be the string-concatenation of keyword, "-", and entry.[[Value]].
     34        c. Append keyword to fullKeywords.
     35    ...
     36 features: [Intl.Locale]
     37 ---*/
     38 
     39 const validCollationOptions = [
     40  ["abc", "en-u-co-abc"],
     41  ["abcd", "en-u-co-abcd"],
     42  ["abcde", "en-u-co-abcde"],
     43  ["abcdef", "en-u-co-abcdef"],
     44  ["abcdefg", "en-u-co-abcdefg"],
     45  ["abcdefgh", "en-u-co-abcdefgh"],
     46  ["12345678", "en-u-co-12345678"],
     47  ["1234abcd", "en-u-co-1234abcd"],
     48  ["1234abcd-abc123", "en-u-co-1234abcd-abc123"],
     49 ];
     50 for (const [collation, expected] of validCollationOptions) {
     51  assert.sameValue(
     52    new Intl.Locale('en', {collation}).toString(),
     53    expected,
     54    `new Intl.Locale('en', {collation: "${collation}"}).toString() returns "${expected}"`
     55  );
     56 
     57  assert.sameValue(
     58    new Intl.Locale('en-u-co-gregory', {collation}).toString(),
     59    expected,
     60    `new Intl.Locale('en-u-co-gregory', {collation: "${collation}"}).toString() returns "${expected}"`
     61  );
     62 }
     63 
     64 reportCompare(0, 0);