michael@0: // Copyright 2012 Mozilla Corporation. All rights reserved. michael@0: // This code is governed by the BSD license found in the LICENSE file. michael@0: michael@0: /** michael@0: * @description Tests that format function is bound to its Intl.NumberFormat. michael@0: * @author Norbert Lindenberg michael@0: */ michael@0: michael@0: $INCLUDE("testIntl.js"); michael@0: michael@0: var numbers = [0, -0, 1, -1, 5.5, 123, -123, -123.45, 123.44501, 0.001234, michael@0: -0.00000000123, 0.00000000000000000000000000000123, 1.2, 0.0000000012344501, michael@0: 123445.01, 12344501000000000000000000000000000, -12344501000000000000000000000000000, michael@0: Infinity, -Infinity, NaN]; michael@0: var locales = [undefined, ["de"], ["th-u-nu-thai"], ["en"], ["ja-u-nu-jpanfin"], ["ar-u-nu-arab"]]; michael@0: var options = [ michael@0: undefined, michael@0: {style: "percent"}, michael@0: {style: "currency", currency: "EUR", currencyDisplay: "symbol"}, michael@0: {style: "currency", currency: "IQD", currencyDisplay: "symbol"}, michael@0: {style: "currency", currency: "KMF", currencyDisplay: "symbol"}, michael@0: {style: "currency", currency: "CLF", currencyDisplay: "symbol"}, michael@0: {useGrouping: false, minimumIntegerDigits: 3, minimumFractionDigits: 1, maximumFractionDigits: 3} michael@0: ]; michael@0: michael@0: locales.forEach(function (locales) { michael@0: options.forEach(function (options) { michael@0: var formatObj = new Intl.NumberFormat(locales, options); michael@0: var formatFunc = formatObj.format; michael@0: numbers.forEach(function (number) { michael@0: var referenceFormatted = formatObj.format(number); michael@0: var formatted = formatFunc(number); michael@0: if (referenceFormatted !== formatted) { michael@0: $ERROR("format function produces different result than format method for locales " + michael@0: locales + "; options: " + (options ? JSON.stringify(options) : options) + michael@0: " : " + formatted + " vs. " + referenceFormatted + "."); michael@0: } michael@0: }); michael@0: }); michael@0: }); michael@0: