summaryrefslogtreecommitdiff
path: root/test/suite/intl402/ch11/11.3/11.3.2_1_c.js
blob: 3fc877b310b56c68895d67f54a8d383d00e5ca93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2012 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/**
 * @description Tests that format function is bound to its Intl.NumberFormat.
 * @author Norbert Lindenberg
 */

$INCLUDE("testIntl.js");

var numbers = [0, -0, 1, -1, 5.5, 123, -123, -123.45, 123.44501, 0.001234,
    -0.00000000123, 0.00000000000000000000000000000123, 1.2, 0.0000000012344501,
    123445.01, 12344501000000000000000000000000000, -12344501000000000000000000000000000,
    Infinity, -Infinity, NaN];
var locales = [undefined, ["de"], ["th-u-nu-thai"], ["en"], ["ja-u-nu-jpanfin"], ["ar-u-nu-arab"]];
var options = [
    undefined,
    {style: "percent"},
    {style: "currency", currency: "EUR", currencyDisplay: "symbol"},
    {style: "currency", currency: "IQD", currencyDisplay: "symbol"},
    {style: "currency", currency: "KMF", currencyDisplay: "symbol"},
    {style: "currency", currency: "CLF", currencyDisplay: "symbol"},
    {useGrouping: false, minimumIntegerDigits: 3, minimumFractionDigits: 1, maximumFractionDigits: 3}
];

locales.forEach(function (locales) {
    options.forEach(function (options) {
        var formatObj = new Intl.NumberFormat(locales, options);
        var formatFunc = formatObj.format;
        numbers.forEach(function (number) {
            var referenceFormatted = formatObj.format(number);
            var formatted = formatFunc(number);
            if (referenceFormatted !== formatted) {
                $ERROR("format function produces different result than format method for locales " +
                    locales + "; options: " + (options ? JSON.stringify(options) : options) +
                    " : " + formatted + " vs. " + referenceFormatted + ".");
            }
        });
    });
});