|
1 // Copyright 2012 Mozilla Corporation. All rights reserved. |
|
2 // This code is governed by the BSD license found in the LICENSE file. |
|
3 |
|
4 /** |
|
5 * @description Tests that the options numeric and caseFirst can be |
|
6 * set through either the locale or the options. |
|
7 * @author Norbert Lindenberg |
|
8 */ |
|
9 |
|
10 $INCLUDE("testIntl.js"); |
|
11 |
|
12 var options = [ |
|
13 {key: "kn", property: "numeric", type: "boolean", values: [true, false]}, |
|
14 {key: "kf", property: "caseFirst", type: "string", values: ["upper", "lower", "false"]} |
|
15 ]; |
|
16 |
|
17 options.forEach(function (option) { |
|
18 var defaultLocale = new Intl.Collator().resolvedOptions().locale; |
|
19 var collator, opt, result; |
|
20 |
|
21 // find out which values are supported for a property in the default locale |
|
22 var supportedValues = []; |
|
23 option.values.forEach(function (value) { |
|
24 opt = {}; |
|
25 opt[option.property] = value; |
|
26 collator = new Intl.Collator([defaultLocale], opt); |
|
27 result = collator.resolvedOptions()[option.property]; |
|
28 if (result !== undefined && supportedValues.indexOf(result) === -1) { |
|
29 supportedValues.push(result); |
|
30 } |
|
31 }); |
|
32 |
|
33 // verify that the supported values can also be set through the locale |
|
34 supportedValues.forEach(function (value) { |
|
35 collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + value]); |
|
36 result = collator.resolvedOptions()[option.property]; |
|
37 if (result !== value) { |
|
38 $ERROR("Property " + option.property + " couldn't be set through locale extension key " + |
|
39 option.key + "; requested value: " + value + "; actual value: " + result + "."); |
|
40 } |
|
41 }); |
|
42 |
|
43 // verify that the options setting overrides the locale setting |
|
44 supportedValues.forEach(function (value) { |
|
45 var otherValue; |
|
46 option.values.forEach(function (possibleValue) { |
|
47 if (possibleValue !== value) { |
|
48 otherValue = possibleValue; |
|
49 } |
|
50 }); |
|
51 if (otherValue !== undefined) { |
|
52 opt = {}; |
|
53 opt[option.property] = value; |
|
54 collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + otherValue], opt); |
|
55 result = collator.resolvedOptions()[option.property]; |
|
56 if (result !== value) { |
|
57 $ERROR("Options value for property " + option.property + " doesn't override locale extension key " + |
|
58 option.key + "; requested value: " + value + "; actual value: " + result + "."); |
|
59 } |
|
60 } |
|
61 }); |
|
62 }); |
|
63 |