tor-browser

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

reject-duplicate-variants.js (1536B)


      1 // Copyright 2020 Jeff Walden, Mozilla Corporation. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-isstructurallyvalidlanguagetag
      6 description: >
      7  Verifies that duplicate variants in a tag ("en-emodeng-emodeng") make the tag
      8  structurally invalid.
      9 info: |
     10  the `unicode_language_id` within _locale_ contains no duplicate
     11  `unicode_variant_subtag` subtags
     12 features: [Intl.Locale]
     13 ---*/
     14 
     15 assert.sameValue(typeof Intl.Locale, "function");
     16 
     17 function mustReject(tag) {
     18  assert.throws(RangeError, () => {
     19    // Direct matches are rejected.
     20    new Intl.Locale(tag);
     21  }, `tag "${tag}" must be considered structurally invalid`);
     22 }
     23 
     24 // BCP47 since forever, and ECMA-402 as consequence, do not consider tags that
     25 // contain duplicate variants to be structurally valid.
     26 
     27 // Direct matches are rejected.
     28 mustReject("en-emodeng-emodeng");
     29 // Case-insensitive matches are also rejected.
     30 mustReject("en-Emodeng-emodeng");
     31 // ...and in either order.
     32 mustReject("en-emodeng-Emodeng");
     33 
     34 // Repeat the above tests with additional variants interspersed at each point
     35 // for completeness.
     36 mustReject("en-variant-emodeng-emodeng");
     37 mustReject("en-variant-Emodeng-emodeng");
     38 mustReject("en-variant-emodeng-Emodeng");
     39 mustReject("en-emodeng-variant-emodeng");
     40 mustReject("en-Emodeng-variant-emodeng");
     41 mustReject("en-emodeng-variant-Emodeng");
     42 mustReject("en-emodeng-emodeng-variant");
     43 mustReject("en-Emodeng-emodeng-variant");
     44 mustReject("en-emodeng-Emodeng-variant");
     45 
     46 reportCompare(0, 0);