js/src/tests/test262/intl402/ch10/10.2/10.2.3_b.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial