Bug 1445465 - Part 3: Update tests. r=Waldo
authorAndré Bargull <andre.bargull@gmail.com>
Tue, 27 Mar 2018 07:40:40 -0700
changeset 410609 3214fb35ccd684ada1d5cd230563c80b7f795fe7
parent 410608 b8ff6d9ecca3199c1b6721645c17c46f8a860cd3
child 410610 122d31260faaad8981c779d3f90fe56bdcdcfa8a
push id101534
push userdluca@mozilla.com
push dateThu, 29 Mar 2018 13:46:53 +0000
treeherdermozilla-inbound@122d31260faa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1445465
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1445465 - Part 3: Update tests. r=Waldo
js/src/tests/non262/Intl/NumberFormat/StringBuffer.js
js/src/tests/non262/Intl/NumberFormat/formatToParts.js
--- a/js/src/tests/non262/Intl/NumberFormat/StringBuffer.js
+++ b/js/src/tests/non262/Intl/NumberFormat/StringBuffer.js
@@ -5,13 +5,33 @@
 
 // The implementation of the format function uses the C++ StringBuffer class,
 // which changes its storage model at 32 characters, and uses it in a way which
 // also means that there's no room for null-termination at this limit.
 // This test makes sure that none of this affects the output.
 
 var format = new Intl.NumberFormat("it-IT", {minimumFractionDigits: 1});
 
-assertEq(format.format(1123123123123123123123.1), "1.123.123.123.123.120.000.000,0");
-assertEq(format.format(12123123123123123123123.1), "12.123.123.123.123.100.000.000,0");
-assertEq(format.format(123123123123123123123123.1), "123.123.123.123.123.000.000.000,0");
+assertEq(format.format(1123123123123123123123.1), "1.123.123.123.123.123.100.000,0");
+assertEq(format.format(12123123123123123123123.1), "12.123.123.123.123.122.000.000,0");
+assertEq(format.format(123123123123123123123123.1), "123.123.123.123.123.120.000.000,0");
+
+// Ensure the ICU output matches Number.prototype.toFixed.
+function formatToFixed(x) {
+    var mfd = format.resolvedOptions().maximumFractionDigits;
+    var s = x.toFixed(mfd);
+
+    // To keep it simple we assume |s| is always in exponential form.
+    var m = s.match(/^(\d)\.(\d+)e\+(\d+)$/);
+    assertEq(m !== null, true);
+    s = m[1] + m[2].padEnd(m[3], "0");
+
+    // Group digits and append fractional part.
+    m = s.match(/\d{1,3}(?=(?:\d{3})*$)/g);
+    assertEq(m !== null, true);
+    return m.join(".") + ",0";
+}
+
+assertEq(formatToFixed(1123123123123123123123.1), "1.123.123.123.123.123.100.000,0");
+assertEq(formatToFixed(12123123123123123123123.1), "12.123.123.123.123.122.000.000,0");
+assertEq(formatToFixed(123123123123123123123123.1), "123.123.123.123.123.120.000.000,0");
 
 reportCompare(0, 0, "ok");
--- a/js/src/tests/non262/Intl/NumberFormat/formatToParts.js
+++ b/js/src/tests/non262/Intl/NumberFormat/formatToParts.js
@@ -210,17 +210,16 @@ var arPercentFormatter =
 
 assertParts(arPercentFormatter, -135.32,
             [MinusSign("\u{061C}-"),
              Integer("١٣"),
              Group("٬"),
              Integer("٥٣٢"),
              Decimal("٫"),
              Fraction("٠٠"),
-             Literal("\xA0"),
              PercentSign("٪\u{061C}")]);
 
 // Decimals.
 
 var usDecimalOptions =
   {
     style: "decimal",
     maximumFractionDigits: 7 // minimum defaults to 0