js/src/tests/Intl/NumberFormat/format.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 // Tests the format function with a diverse set of locales and options.
michael@0 7
michael@0 8 var format;
michael@0 9
michael@0 10 // Locale en-US; default options.
michael@0 11 format = new Intl.NumberFormat("en-us");
michael@0 12 assertEq(format.format(0), "0");
michael@0 13 assertEq(format.format(-1), "-1");
michael@0 14 assertEq(format.format(123456789.123456789), "123,456,789.123");
michael@0 15
michael@0 16 // Locale en-US; currency USD.
michael@0 17 // The US dollar uses two fractional digits, and negative values are commonly
michael@0 18 // parenthesized.
michael@0 19 format = new Intl.NumberFormat("en-us", {style: "currency", currency: "USD"});
michael@0 20 assertEq(format.format(0), "$0.00");
michael@0 21 assertEq(format.format(-1), "-$1.00");
michael@0 22 assertEq(format.format(123456789.123456789), "$123,456,789.12");
michael@0 23
michael@0 24 // Locale ja-JP; currency JPY.
michael@0 25 // The Japanese yen has no subunit in real life.
michael@0 26 format = new Intl.NumberFormat("ja-jp", {style: "currency", currency: "JPY"});
michael@0 27 assertEq(format.format(0), "¥0");
michael@0 28 assertEq(format.format(-1), "-¥1");
michael@0 29 assertEq(format.format(123456789.123456789), "¥123,456,789");
michael@0 30
michael@0 31 // Locale ar-JO; currency JOD.
michael@0 32 // The Jordanian Dinar divides into 1000 fils. Jordan uses (real) Arabic digits.
michael@0 33 format = new Intl.NumberFormat("ar-jo", {style: "currency", currency: "JOD"});
michael@0 34 assertEq(format.format(0), "د.أ.‏ ٠٫٠٠٠");
michael@0 35 assertEq(format.format(-1), "‏-د.أ.‏ ١٫٠٠٠");
michael@0 36 assertEq(format.format(123456789.123456789), "د.أ.‏ ١٢٣٬٤٥٦٬٧٨٩٫١٢٣");
michael@0 37
michael@0 38 // Locale th-TH; Thai digits, percent, two significant digits.
michael@0 39 format = new Intl.NumberFormat("th-th-u-nu-thai",
michael@0 40 {style: "percent",
michael@0 41 minimumSignificantDigits: 2,
michael@0 42 maximumSignificantDigits: 2});
michael@0 43 assertEq(format.format(0), "๐.๐%");
michael@0 44 assertEq(format.format(-0.01), "-๑.๐%");
michael@0 45 assertEq(format.format(1.10), "๑๑๐%");
michael@0 46
michael@0 47 reportCompare(0, 0, 'ok');

mercurial