tor-browser

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

transformed-ext-valid.js (2142B)


      1 // Copyright (C) 2020 André Bargull. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-intl.getcanonicallocales
      6 description: >
      7  No RangeError is thrown when a language tag includes a valid transformed extension subtag.
      8 info: |
      9  8.2.1 Intl.getCanonicalLocales (locales)
     10    1. Let ll be ? CanonicalizeLocaleList(locales).
     11    2. Return CreateArrayFromList(ll).
     12 
     13  9.2.1 CanonicalizeLocaleList (locales)
     14    ...
     15    7. Repeat, while k < len
     16      ...
     17      c. If kPresent is true, then
     18        ...
     19        v. If IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
     20        vi. Let canonicalizedTag be CanonicalizeUnicodeLocaleId(tag).
     21        ...
     22 
     23 includes: [testIntl.js]
     24 ---*/
     25 
     26 const valid = [
     27  // tlang with unicode_language_subtag.
     28  "en-t-en",
     29 
     30  // tlang with unicode_script_subtag.
     31  "en-t-en-latn",
     32 
     33  // tlang with unicode_region_subtag.
     34  "en-t-en-ca",
     35 
     36  // tlang with unicode_script_subtag and unicode_region_subtag.
     37  "en-t-en-latn-ca",
     38 
     39  // tlang with unicode_variant_subtag.
     40  "en-t-en-emodeng",
     41 
     42  // tlang with unicode_script_subtag and unicode_variant_subtag.
     43  "en-t-en-latn-emodeng",
     44 
     45  // tlang with unicode_script_subtag and unicode_variant_subtag.
     46  "en-t-en-ca-emodeng",
     47 
     48  // tlang with unicode_script_subtag, unicode_region_subtag, and unicode_variant_subtag.
     49  "en-t-en-latn-ca-emodeng",
     50 
     51  // No tlang. (Must contain at least one tfield.)
     52  "en-t-d0-ascii",
     53 ];
     54 
     55 const extraFields = [
     56  // No extra tfield
     57  "",
     58 
     59  // tfield with a tvalue consisting of a single subtag.
     60  "-i0-handwrit",
     61 
     62  // tfield with a tvalue consisting of two subtags.
     63  "-s0-accents-publish",
     64 ];
     65 
     66 for (let tag of valid) {
     67  for (let extra of extraFields) {
     68    let actualTag = tag + extra;
     69 
     70    // Make sure the test data is correct.
     71    assert(isCanonicalizedStructurallyValidLanguageTag(actualTag),
     72           "\"" + actualTag + "\" is a canonical and structurally valid language tag.");
     73 
     74    let result = Intl.getCanonicalLocales(actualTag);
     75    assert.sameValue(result.length, 1);
     76    assert.sameValue(result[0], actualTag);
     77  }
     78 }
     79 
     80 reportCompare(0, 0);