tor-browser

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

ignore-invalid-unicode-ext-values.js (1959B)


      1 // Copyright 2012 Mozilla Corporation. All rights reserved.
      2 // This code is governed by the license found in the LICENSE file.
      3 
      4 /*---
      5 es5id: 10.2.3_b
      6 description: >
      7    Tests that Intl.Collator does not accept Unicode locale  extension
      8    keys and values that are not allowed.
      9 author: Norbert Lindenberg
     10 includes: [compareArray.js]
     11 ---*/
     12 
     13 var testArray = [
     14        "hello", "你好", "こんにちは",
     15        "pêche", "peché", "1", "9", "10",
     16        "ụ\u031B", "u\u031B\u0323", "ư\u0323", "u\u0323\u031B",
     17        "Å", "Å", "A\u030A"
     18 ];
     19 
     20 var defaultCollator = new Intl.Collator();
     21 var defaultOptions = defaultCollator.resolvedOptions();
     22 var defaultOptionsJSON = JSON.stringify(defaultOptions);
     23 var defaultLocale = defaultOptions.locale;
     24 var defaultSortedArray = testArray.slice(0).sort(defaultCollator.compare);
     25 
     26 var keyValues = {
     27    "co": ["standard", "search", "invalid"],
     28    "ka": ["noignore", "shifted", "invalid"],
     29    "kb": ["true", "false", "invalid"],
     30    "kc": ["true", "false", "invalid"],
     31    "kh": ["true", "false", "invalid"],
     32    "kk": ["true", "false", "invalid"],
     33    "kr": ["latn-hira-hani", "hani-hira-latn", "invalid"],
     34    "ks": ["level1", "level2", "level3", "level4", "identic", "invalid"],
     35    "vt": ["1234-5678-9abc-edf0", "invalid"]
     36 };
     37 
     38 Object.getOwnPropertyNames(keyValues).forEach(function (key) {
     39    keyValues[key].forEach(function (value) {
     40        var collator = new Intl.Collator([defaultLocale + "-u-" + key + "-" + value]);
     41        var options = collator.resolvedOptions();
     42        assert.sameValue(options.locale, defaultLocale, "Locale " + options.locale + " is affected by key " + key + "; value " + value + ".");
     43        assert.sameValue(JSON.stringify(options), defaultOptionsJSON, "Resolved options " + JSON.stringify(options) + " are affected by key " + key + "; value " + value + ".");
     44        assert.compareArray(testArray.sort(collator.compare), defaultSortedArray);
     45    });
     46 });
     47 
     48 reportCompare(0, 0);