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.

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

mercurial