js/src/tests/test262/intl402/ch11/11.3/11.3.2_1_c.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_1_c.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,41 @@
     1.4 +// Copyright 2012 Mozilla Corporation. All rights reserved.
     1.5 +// This code is governed by the BSD license found in the LICENSE file.
     1.6 +
     1.7 +/**
     1.8 + * @description Tests that format function is bound to its Intl.NumberFormat.
     1.9 + * @author Norbert Lindenberg
    1.10 + */
    1.11 +
    1.12 +$INCLUDE("testIntl.js");
    1.13 +
    1.14 +var numbers = [0, -0, 1, -1, 5.5, 123, -123, -123.45, 123.44501, 0.001234,
    1.15 +    -0.00000000123, 0.00000000000000000000000000000123, 1.2, 0.0000000012344501,
    1.16 +    123445.01, 12344501000000000000000000000000000, -12344501000000000000000000000000000,
    1.17 +    Infinity, -Infinity, NaN];
    1.18 +var locales = [undefined, ["de"], ["th-u-nu-thai"], ["en"], ["ja-u-nu-jpanfin"], ["ar-u-nu-arab"]];
    1.19 +var options = [
    1.20 +    undefined,
    1.21 +    {style: "percent"},
    1.22 +    {style: "currency", currency: "EUR", currencyDisplay: "symbol"},
    1.23 +    {style: "currency", currency: "IQD", currencyDisplay: "symbol"},
    1.24 +    {style: "currency", currency: "KMF", currencyDisplay: "symbol"},
    1.25 +    {style: "currency", currency: "CLF", currencyDisplay: "symbol"},
    1.26 +    {useGrouping: false, minimumIntegerDigits: 3, minimumFractionDigits: 1, maximumFractionDigits: 3}
    1.27 +];
    1.28 +
    1.29 +locales.forEach(function (locales) {
    1.30 +    options.forEach(function (options) {
    1.31 +        var formatObj = new Intl.NumberFormat(locales, options);
    1.32 +        var formatFunc = formatObj.format;
    1.33 +        numbers.forEach(function (number) {
    1.34 +            var referenceFormatted = formatObj.format(number);
    1.35 +            var formatted = formatFunc(number);
    1.36 +            if (referenceFormatted !== formatted) {
    1.37 +                $ERROR("format function produces different result than format method for locales " +
    1.38 +                    locales + "; options: " + (options ? JSON.stringify(options) : options) +
    1.39 +                    " : " + formatted + " vs. " + referenceFormatted + ".");
    1.40 +            }
    1.41 +        });
    1.42 +    });
    1.43 +});
    1.44 +

mercurial