js/src/tests/test262/intl402/ch11/11.2/11.2.3_b.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     1 // Copyright 2012 Mozilla Corporation. All rights reserved.
     2 // This code is governed by the license found in the LICENSE file.
     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  */
    10 $INCLUDE("testIntl.js");
    12 var locales = ["ja-JP", "zh-Hans-CN", "zh-Hant-TW"];
    13 var input = 1234567.89;
    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);
    22     var keyValues = {
    23         "cu": ["USD", "EUR", "JPY", "CNY", "TWD", "invalid"],
    24         "nu": ["native", "traditio", "finance", "invalid"]
    25     };
    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 });

mercurial