1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/test262/intl402/ch11/11.2/11.2.3_b.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,46 @@ 1.4 +// Copyright 2012 Mozilla Corporation. All rights reserved. 1.5 +// This code is governed by the license found in the LICENSE file. 1.6 + 1.7 +/** 1.8 + * @description Tests that Intl.NumberFormat does not accept Unicode locale 1.9 + * extension keys and values that are not allowed. 1.10 + * @author Norbert Lindenberg 1.11 + */ 1.12 + 1.13 +$INCLUDE("testIntl.js"); 1.14 + 1.15 +var locales = ["ja-JP", "zh-Hans-CN", "zh-Hant-TW"]; 1.16 +var input = 1234567.89; 1.17 + 1.18 +locales.forEach(function (locale) { 1.19 + var defaultNumberFormat = new Intl.NumberFormat([locale]); 1.20 + var defaultOptions = defaultNumberFormat.resolvedOptions(); 1.21 + var defaultOptionsJSON = JSON.stringify(defaultOptions); 1.22 + var defaultLocale = defaultOptions.locale; 1.23 + var defaultFormatted = defaultNumberFormat.format(input); 1.24 + 1.25 + var keyValues = { 1.26 + "cu": ["USD", "EUR", "JPY", "CNY", "TWD", "invalid"], 1.27 + "nu": ["native", "traditio", "finance", "invalid"] 1.28 + }; 1.29 + 1.30 + Object.getOwnPropertyNames(keyValues).forEach(function (key) { 1.31 + keyValues[key].forEach(function (value) { 1.32 + var numberFormat = new Intl.NumberFormat([locale + "-u-" + key + "-" + value]); 1.33 + var options = numberFormat.resolvedOptions(); 1.34 + if (options.locale !== defaultLocale) { 1.35 + $ERROR("Locale " + options.locale + " is affected by key " + 1.36 + key + "; value " + value + "."); 1.37 + } 1.38 + if (JSON.stringify(options) !== defaultOptionsJSON) { 1.39 + $ERROR("Resolved options " + JSON.stringify(options) + " are affected by key " + 1.40 + key + "; value " + value + "."); 1.41 + } 1.42 + if (defaultFormatted !== numberFormat.format(input)) { 1.43 + $ERROR("Formatted value " + numberFormat.format(input) + " is affected by key " + 1.44 + key + "; value " + value + "."); 1.45 + } 1.46 + }); 1.47 + }); 1.48 +}); 1.49 +