michael@0: // Copyright 2012 Mozilla Corporation. All rights reserved. michael@0: // This code is governed by the license found in the LICENSE file. michael@0: michael@0: /** michael@0: * @description Tests that Intl.NumberFormat does not accept Unicode locale michael@0: * extension keys and values that are not allowed. michael@0: * @author Norbert Lindenberg michael@0: */ michael@0: michael@0: $INCLUDE("testIntl.js"); michael@0: michael@0: var locales = ["ja-JP", "zh-Hans-CN", "zh-Hant-TW"]; michael@0: var input = 1234567.89; michael@0: michael@0: locales.forEach(function (locale) { michael@0: var defaultNumberFormat = new Intl.NumberFormat([locale]); michael@0: var defaultOptions = defaultNumberFormat.resolvedOptions(); michael@0: var defaultOptionsJSON = JSON.stringify(defaultOptions); michael@0: var defaultLocale = defaultOptions.locale; michael@0: var defaultFormatted = defaultNumberFormat.format(input); michael@0: michael@0: var keyValues = { michael@0: "cu": ["USD", "EUR", "JPY", "CNY", "TWD", "invalid"], michael@0: "nu": ["native", "traditio", "finance", "invalid"] michael@0: }; michael@0: michael@0: Object.getOwnPropertyNames(keyValues).forEach(function (key) { michael@0: keyValues[key].forEach(function (value) { michael@0: var numberFormat = new Intl.NumberFormat([locale + "-u-" + key + "-" + value]); michael@0: var options = numberFormat.resolvedOptions(); michael@0: if (options.locale !== defaultLocale) { michael@0: $ERROR("Locale " + options.locale + " is affected by key " + michael@0: key + "; value " + value + "."); michael@0: } michael@0: if (JSON.stringify(options) !== defaultOptionsJSON) { michael@0: $ERROR("Resolved options " + JSON.stringify(options) + " are affected by key " + michael@0: key + "; value " + value + "."); michael@0: } michael@0: if (defaultFormatted !== numberFormat.format(input)) { michael@0: $ERROR("Formatted value " + numberFormat.format(input) + " is affected by key " + michael@0: key + "; value " + value + "."); michael@0: } michael@0: }); michael@0: }); michael@0: }); michael@0: