aboutsummaryrefslogtreecommitdiffstats
path: root/test/suite/intl402/ch11/11.3
diff options
context:
space:
mode:
authorNorbert Lindenberg <ecmascript@lindenbergsoftware.com>2012-08-26 20:50:24 -0700
committerNorbert Lindenberg <ecmascript@lindenbergsoftware.com>2012-08-26 20:50:24 -0700
commitd71ffa59d5fa2df454bf1c1853b0ccfc87fe3bcd (patch)
tree79aed459cf2d8f9d26f8e0ece825d5e20b1d4650 /test/suite/intl402/ch11/11.3
parent1af24250750e0a4318ec8efb467245fa0e86c215 (diff)
Added new tests for chapters 10 to 13 of the ECMAScript Internationalization API Specification.
Diffstat (limited to 'test/suite/intl402/ch11/11.3')
-rw-r--r--test/suite/intl402/ch11/11.3/11.3.2_1_c.js41
-rw-r--r--test/suite/intl402/ch11/11.3/11.3.2_TRF.js52
-rw-r--r--test/suite/intl402/ch11/11.3/11.3.2_TRP.js52
-rw-r--r--test/suite/intl402/ch11/11.3/11.3.3.js31
-rw-r--r--test/suite/intl402/ch11/11.3/11.3_a.js (renamed from test/suite/intl402/ch11/11.3/11.3.js)0
-rw-r--r--test/suite/intl402/ch11/11.3/11.3_b.js33
6 files changed, 209 insertions, 0 deletions
diff --git a/test/suite/intl402/ch11/11.3/11.3.2_1_c.js b/test/suite/intl402/ch11/11.3/11.3.2_1_c.js
new file mode 100644
index 000000000..3fc877b31
--- /dev/null
+++ b/test/suite/intl402/ch11/11.3/11.3.2_1_c.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 format function is bound to its 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 formatObj = new Intl.NumberFormat(locales, options);
+ var formatFunc = formatObj.format;
+ numbers.forEach(function (number) {
+ var referenceFormatted = formatObj.format(number);
+ var formatted = formatFunc(number);
+ if (referenceFormatted !== formatted) {
+ $ERROR("format function produces different result than format method for locales " +
+ locales + "; options: " + (options ? JSON.stringify(options) : options) +
+ " : " + formatted + " vs. " + referenceFormatted + ".");
+ }
+ });
+ });
+});
+
diff --git a/test/suite/intl402/ch11/11.3/11.3.2_TRF.js b/test/suite/intl402/ch11/11.3/11.3.2_TRF.js
new file mode 100644
index 000000000..32ee5cd9a
--- /dev/null
+++ b/test/suite/intl402/ch11/11.3/11.3.2_TRF.js
@@ -0,0 +1,52 @@
+// Copyright 2011-2012 Norbert Lindenberg. All rights reserved.
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that the digits are determined correctly when specifying pre/post decimal digits.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+var locales = [
+ new Intl.NumberFormat().resolvedOptions().locale,
+ "ar", "de", "th", "ja"
+];
+var numberingSystems = [
+ "arab",
+ "latn",
+ "thai",
+ "hanidec"
+];
+var testData = {
+ "0": "000.0",
+ "-0": "000.0",
+ "123": "123.0",
+ "-123": "-123.0",
+ "12345": "12345.0",
+ "-12345": "-12345.0",
+ "123.45": "123.45",
+ "-123.45": "-123.45",
+ "123.44501": "123.445",
+ "-123.44501": "-123.445",
+ "0.001234": "000.001",
+ "-0.001234": "-000.001",
+ "0.00000000123": "000.0",
+ "-0.00000000123": "-000.0",
+ "0.00000000000000000000000000000123": "000.0",
+ "-0.00000000000000000000000000000123": "-000.0",
+ "1.2": "001.2",
+ "-1.2": "-001.2",
+ "0.0000000012344501": "000.0",
+ "-0.0000000012344501": "-000.0",
+ "123445.01": "123445.01",
+ "-123445.01": "-123445.01",
+ "12344501000000000000000000000000000": "12344501000000000000000000000000000.0",
+ "-12344501000000000000000000000000000": "-12344501000000000000000000000000000.0"
+};
+
+testNumberFormat(locales, numberingSystems,
+ {useGrouping: false, minimumIntegerDigits: 3, minimumFractionDigits: 1, maximumFractionDigits: 3},
+ testData);
+
diff --git a/test/suite/intl402/ch11/11.3/11.3.2_TRP.js b/test/suite/intl402/ch11/11.3/11.3.2_TRP.js
new file mode 100644
index 000000000..9409e258d
--- /dev/null
+++ b/test/suite/intl402/ch11/11.3/11.3.2_TRP.js
@@ -0,0 +1,52 @@
+// Copyright 2011-2012 Norbert Lindenberg. All rights reserved.
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that the digits are determined correctly when specifying significant digits.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+var locales = [
+ new Intl.NumberFormat().resolvedOptions().locale,
+ "ar", "de", "th", "ja"
+];
+var numberingSystems = [
+ "arab",
+ "latn",
+ "thai",
+ "hanidec"
+];
+var testData = {
+ "0": "0.00",
+ "-0": "0.00",
+ "123": "123",
+ "-123": "-123",
+ "12345": "12345",
+ "-12345": "-12345",
+ "123.45": "123.45",
+ "-123.45": "-123.45",
+ "123.44501": "123.45",
+ "-123.44501": "-123.45",
+ "0.001234": "0.001234",
+ "-0.001234": "-0.001234",
+ "0.00000000123": "0.00000000123",
+ "-0.00000000123": "-0.00000000123",
+ "0.00000000000000000000000000000123": "0.00000000000000000000000000000123",
+ "-0.00000000000000000000000000000123": "-0.00000000000000000000000000000123",
+ "1.2": "1.20",
+ "-1.2": "-1.20",
+ "0.0000000012344501": "0.0000000012345",
+ "-0.0000000012344501": "-0.0000000012345",
+ "123445.01": "123450",
+ "-123445.01": "-123450",
+ "12344501000000000000000000000000000": "12345000000000000000000000000000000",
+ "-12344501000000000000000000000000000": "-12345000000000000000000000000000000"
+};
+
+testNumberFormat(locales, numberingSystems,
+ {useGrouping: false, minimumSignificantDigits: 3, maximumSignificantDigits: 5},
+ testData);
+
diff --git a/test/suite/intl402/ch11/11.3/11.3.3.js b/test/suite/intl402/ch11/11.3/11.3.3.js
new file mode 100644
index 000000000..60f9bbbd8
--- /dev/null
+++ b/test/suite/intl402/ch11/11.3/11.3.3.js
@@ -0,0 +1,31 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/**
+ * @description Tests that the object returned by Intl.NumberFormat.prototype.resolvedOptions
+ * has the right properties.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+var actual = new Intl.NumberFormat().resolvedOptions();
+
+var actual2 = new Intl.NumberFormat().resolvedOptions();
+if (actual2 === actual) {
+ $ERROR("resolvedOptions returned the same object twice.");
+}
+
+// this assumes the default values where the specification provides them
+mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag);
+mustHaveProperty(actual, "numberingSystem", isValidNumberingSystem);
+mustHaveProperty(actual, "style", ["decimal"]);
+mustNotHaveProperty(actual, "currency");
+mustNotHaveProperty(actual, "currencyDisplay");
+mustHaveProperty(actual, "minimumIntegerDigits", [1]);
+mustHaveProperty(actual, "minimumFractionDigits", [0]);
+mustHaveProperty(actual, "maximumFractionDigits", [3]);
+mustNotHaveProperty(actual, "minimumSignificantDigits");
+mustNotHaveProperty(actual, "maximumSignificantDigits");
+mustHaveProperty(actual, "useGrouping", [true, false]);
+
diff --git a/test/suite/intl402/ch11/11.3/11.3.js b/test/suite/intl402/ch11/11.3/11.3_a.js
index 282a10bf6..282a10bf6 100644
--- a/test/suite/intl402/ch11/11.3/11.3.js
+++ b/test/suite/intl402/ch11/11.3/11.3_a.js
diff --git a/test/suite/intl402/ch11/11.3/11.3_b.js b/test/suite/intl402/ch11/11.3/11.3_b.js
new file mode 100644
index 000000000..6d0162b1d
--- /dev/null
+++ b/test/suite/intl402/ch11/11.3/11.3_b.js
@@ -0,0 +1,33 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that Intl.NumberFormat.prototype functions throw a
+ * TypeError if called on a non-object value or an object that hasn't been
+ * initialized as a NumberFormat.
+ * @author Norbert Lindenberg
+ */
+
+var functions = {
+ "format getter": Object.getOwnPropertyDescriptor(Intl.NumberFormat.prototype, "format").get,
+ resolvedOptions: Intl.NumberFormat.prototype.resolvedOptions
+};
+var invalidTargets = [undefined, null, true, 0, "NumberFormat", [], {}];
+
+Object.getOwnPropertyNames(functions).forEach(function (functionName) {
+ var f = functions[functionName];
+ invalidTargets.forEach(function (target) {
+ var error;
+ try {
+ f.call(target);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Calling " + functionName + " on " + target + " was not rejected.");
+ } else if (error.name !== "TypeError") {
+ $ERROR("Calling " + functionName + " on " + target + " was rejected with wrong error " + error.name + ".");
+ }
+ });
+});
+