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