|
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.NumberFormat 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 locales = ["ja-JP", "zh-Hans-CN", "zh-Hant-TW"]; |
|
13 var input = 1234567.89; |
|
14 |
|
15 locales.forEach(function (locale) { |
|
16 var defaultNumberFormat = new Intl.NumberFormat([locale]); |
|
17 var defaultOptions = defaultNumberFormat.resolvedOptions(); |
|
18 var defaultOptionsJSON = JSON.stringify(defaultOptions); |
|
19 var defaultLocale = defaultOptions.locale; |
|
20 var defaultFormatted = defaultNumberFormat.format(input); |
|
21 |
|
22 var keyValues = { |
|
23 "cu": ["USD", "EUR", "JPY", "CNY", "TWD", "invalid"], |
|
24 "nu": ["native", "traditio", "finance", "invalid"] |
|
25 }; |
|
26 |
|
27 Object.getOwnPropertyNames(keyValues).forEach(function (key) { |
|
28 keyValues[key].forEach(function (value) { |
|
29 var numberFormat = new Intl.NumberFormat([locale + "-u-" + key + "-" + value]); |
|
30 var options = numberFormat.resolvedOptions(); |
|
31 if (options.locale !== defaultLocale) { |
|
32 $ERROR("Locale " + options.locale + " is affected by key " + |
|
33 key + "; value " + value + "."); |
|
34 } |
|
35 if (JSON.stringify(options) !== defaultOptionsJSON) { |
|
36 $ERROR("Resolved options " + JSON.stringify(options) + " are affected by key " + |
|
37 key + "; value " + value + "."); |
|
38 } |
|
39 if (defaultFormatted !== numberFormat.format(input)) { |
|
40 $ERROR("Formatted value " + numberFormat.format(input) + " is affected by key " + |
|
41 key + "; value " + value + "."); |
|
42 } |
|
43 }); |
|
44 }); |
|
45 }); |
|
46 |