js/src/tests/test262/intl402/ch13/13.2/13.2.1_5.js

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     1 // Copyright 2012 Mozilla Corporation. All rights reserved.
     2 // This code is governed by the BSD license found in the LICENSE file.
     4 /**
     5  * @description Tests that Number.prototype.toLocaleString produces the same results as Intl.NumberFormat.
     6  * @author Norbert Lindenberg
     7  */
     9 $INCLUDE("testIntl.js");
    11 var numbers = [0, -0, 1, -1, 5.5, 123, -123, -123.45, 123.44501, 0.001234,
    12     -0.00000000123, 0.00000000000000000000000000000123, 1.2, 0.0000000012344501,
    13     123445.01, 12344501000000000000000000000000000, -12344501000000000000000000000000000,
    14     Infinity, -Infinity, NaN];
    15 var locales = [undefined, ["de"], ["th-u-nu-thai"], ["en"], ["ja-u-nu-jpanfin"], ["ar-u-nu-arab"]];
    16 var options = [
    17     undefined,
    18     {style: "percent"},
    19     {style: "currency", currency: "EUR", currencyDisplay: "symbol"},
    20     {style: "currency", currency: "IQD", currencyDisplay: "symbol"},
    21     {style: "currency", currency: "KMF", currencyDisplay: "symbol"},
    22     {style: "currency", currency: "CLF", currencyDisplay: "symbol"},
    23     {useGrouping: false, minimumIntegerDigits: 3, minimumFractionDigits: 1, maximumFractionDigits: 3}
    24 ];
    26 locales.forEach(function (locales) {
    27     options.forEach(function (options) {
    28         var referenceNumberFormat = new Intl.NumberFormat(locales, options);
    29         var referenceFormatted = numbers.map(referenceNumberFormat.format);
    31         var formatted = numbers.map(function (a) { return a.toLocaleString(locales, options); });
    32         try {
    33             testArraysAreSame(referenceFormatted, formatted);
    34         } catch (e) {
    35             e.message += " (Testing with locales " + locales + "; options " +
    36             (options ? JSON.stringify(options) : options) + ".)";
    37             throw e;
    38         }
    39     });
    40 });

mercurial