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