summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/ch13/13.2
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/intl402/ch13/13.2')
-rw-r--r--js/src/tests/test262/intl402/ch13/13.2/13.2.1_1.js37
-rw-r--r--js/src/tests/test262/intl402/ch13/13.2/13.2.1_4_1.js67
-rw-r--r--js/src/tests/test262/intl402/ch13/13.2/13.2.1_4_2.js13
-rw-r--r--js/src/tests/test262/intl402/ch13/13.2/13.2.1_5.js41
-rw-r--r--js/src/tests/test262/intl402/ch13/13.2/13.2.1_L15.js14
-rw-r--r--js/src/tests/test262/intl402/ch13/13.2/browser.js0
-rw-r--r--js/src/tests/test262/intl402/ch13/13.2/shell.js0
7 files changed, 172 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/ch13/13.2/13.2.1_1.js b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_1.js
new file mode 100644
index 000000000..da1ee8fe5
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_1.js
@@ -0,0 +1,37 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that toLocaleString handles "this Number value" correctly.
+ * @author Norbert Lindenberg
+ */
+
+var invalidValues = [undefined, null, "5", false, {valueOf: function () { return 5; }}];
+var validValues = [5, NaN, -1234567.89, -Infinity];
+
+invalidValues.forEach(function (value) {
+ var error;
+ try {
+ var result = Number.prototype.toLocaleString.call(value);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Number.prototype.toLocaleString did not reject this = " + value + ".");
+ } else if (error.name !== "TypeError") {
+ $ERROR("Number.prototype.toLocaleString rejected this = " + value + " with wrong error " + error.name + ".");
+ }
+});
+
+// for valid values, just check that a Number value and the corresponding
+// Number object get the same result.
+validValues.forEach(function (value) {
+ var Constructor = Number; // to keep jshint happy
+ var valueResult = Number.prototype.toLocaleString.call(value);
+ var objectResult = Number.prototype.toLocaleString.call(new Constructor(value));
+ if (valueResult !== objectResult) {
+ $ERROR("Number.prototype.toLocaleString produces different results for Number value " +
+ value + " and corresponding Number object: " + valueResult + " vs. " + objectResult + ".");
+ }
+});
+
diff --git a/js/src/tests/test262/intl402/ch13/13.2/13.2.1_4_1.js b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_4_1.js
new file mode 100644
index 000000000..e6e0b1163
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_4_1.js
@@ -0,0 +1,67 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that Number.prototype.toLocaleString throws the same exceptions as Intl.NumberFormat.
+ * @author Norbert Lindenberg
+ */
+
+var locales = [null, [NaN], ["i"], ["de_DE"]];
+var options = [
+ {localeMatcher: null},
+ {style: "invalid"},
+ {style: "currency"},
+ {style: "currency", currency: "ßP"},
+ {maximumSignificantDigits: -Infinity}
+];
+
+locales.forEach(function (locales) {
+ var referenceError, error;
+ try {
+ var format = new Intl.NumberFormat(locales);
+ } catch (e) {
+ referenceError = e;
+ }
+ if (referenceError === undefined) {
+ $ERROR("Internal error: Expected exception was not thrown by Intl.NumberFormat for locales " + locales + ".");
+ }
+
+ try {
+ var result = (0).toLocaleString(locales);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Number.prototype.toLocaleString didn't throw exception for locales " + locales + ".");
+ } else if (error.name !== referenceError.name) {
+ $ERROR("Number.prototype.toLocaleString threw exception " + error.name +
+ " for locales " + locales + "; expected " + referenceError.name + ".");
+ }
+});
+
+options.forEach(function (options) {
+ var referenceError, error;
+ try {
+ var format = new Intl.NumberFormat([], options);
+ } catch (e) {
+ referenceError = e;
+ }
+ if (referenceError === undefined) {
+ $ERROR("Internal error: Expected exception was not thrown by Intl.NumberFormat for options " +
+ JSON.stringify(options) + ".");
+ }
+
+ try {
+ var result = (0).toLocaleString([], options);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Number.prototype.toLocaleString didn't throw exception for options " +
+ JSON.stringify(options) + ".");
+ } else if (error.name !== referenceError.name) {
+ $ERROR("Number.prototype.toLocaleString threw exception " + error.name +
+ " for options " + JSON.stringify(options) + "; expected " + referenceError.name + ".");
+ }
+});
+
diff --git a/js/src/tests/test262/intl402/ch13/13.2/13.2.1_4_2.js b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_4_2.js
new file mode 100644
index 000000000..a79cfffde
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_4_2.js
@@ -0,0 +1,13 @@
+// Copyright 2013 Mozilla Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/**
+ * @description Tests that Number.prototype.toLocaleString uses the standard
+ * built-in Intl.NumberFormat constructor.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+taintDataProperty(Intl, "NumberFormat");
+(0.0).toLocaleString();
diff --git a/js/src/tests/test262/intl402/ch13/13.2/13.2.1_5.js b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_5.js
new file mode 100644
index 000000000..eb953b64d
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_5.js
@@ -0,0 +1,41 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that Number.prototype.toLocaleString produces the same results as Intl.NumberFormat.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+var numbers = [0, -0, 1, -1, 5.5, 123, -123, -123.45, 123.44501, 0.001234,
+ -0.00000000123, 0.00000000000000000000000000000123, 1.2, 0.0000000012344501,
+ 123445.01, 12344501000000000000000000000000000, -12344501000000000000000000000000000,
+ Infinity, -Infinity, NaN];
+var locales = [undefined, ["de"], ["th-u-nu-thai"], ["en"], ["ja-u-nu-jpanfin"], ["ar-u-nu-arab"]];
+var options = [
+ undefined,
+ {style: "percent"},
+ {style: "currency", currency: "EUR", currencyDisplay: "symbol"},
+ {style: "currency", currency: "IQD", currencyDisplay: "symbol"},
+ {style: "currency", currency: "KMF", currencyDisplay: "symbol"},
+ {style: "currency", currency: "CLF", currencyDisplay: "symbol"},
+ {useGrouping: false, minimumIntegerDigits: 3, minimumFractionDigits: 1, maximumFractionDigits: 3}
+];
+
+locales.forEach(function (locales) {
+ options.forEach(function (options) {
+ var referenceNumberFormat = new Intl.NumberFormat(locales, options);
+ var referenceFormatted = numbers.map(referenceNumberFormat.format);
+
+ var formatted = numbers.map(function (a) { return a.toLocaleString(locales, options); });
+ try {
+ testArraysAreSame(referenceFormatted, formatted);
+ } catch (e) {
+ e.message += " (Testing with locales " + locales + "; options " +
+ (options ? JSON.stringify(options) : options) + ".)";
+ throw e;
+ }
+ });
+});
+
diff --git a/js/src/tests/test262/intl402/ch13/13.2/13.2.1_L15.js b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_L15.js
new file mode 100644
index 000000000..8b53f7496
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch13/13.2/13.2.1_L15.js
@@ -0,0 +1,14 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/**
+ * @description Tests that Number.prototype.toLocaleString
+ * meets the requirements for built-in objects defined by the introduction of
+ * chapter 15 of the ECMAScript Language Specification.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testBuiltInObject.js");
+
+testBuiltInObject(Number.prototype.toLocaleString, true, false, [], 0);
+
diff --git a/js/src/tests/test262/intl402/ch13/13.2/browser.js b/js/src/tests/test262/intl402/ch13/13.2/browser.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch13/13.2/browser.js
diff --git a/js/src/tests/test262/intl402/ch13/13.2/shell.js b/js/src/tests/test262/intl402/ch13/13.2/shell.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch13/13.2/shell.js