aboutsummaryrefslogtreecommitdiffstats
path: root/test/suite/intl402/ch13
diff options
context:
space:
mode:
Diffstat (limited to 'test/suite/intl402/ch13')
-rw-r--r--test/suite/intl402/ch13/13.1/13.1.1_1.js24
-rw-r--r--test/suite/intl402/ch13/13.1/13.1.1_2.js26
-rw-r--r--test/suite/intl402/ch13/13.1/13.1.1_3.js26
-rw-r--r--test/suite/intl402/ch13/13.1/13.1.1_6.js65
-rw-r--r--test/suite/intl402/ch13/13.1/13.1.1_7.js33
-rw-r--r--test/suite/intl402/ch13/13.2/13.2.1_1.js37
-rw-r--r--test/suite/intl402/ch13/13.2/13.2.1_4.js67
-rw-r--r--test/suite/intl402/ch13/13.2/13.2.1_5.js41
-rw-r--r--test/suite/intl402/ch13/13.3/13.3.0_1.js32
-rw-r--r--test/suite/intl402/ch13/13.3/13.3.0_2.js26
-rw-r--r--test/suite/intl402/ch13/13.3/13.3.0_6.js74
-rw-r--r--test/suite/intl402/ch13/13.3/13.3.0_7.js58
12 files changed, 509 insertions, 0 deletions
diff --git a/test/suite/intl402/ch13/13.1/13.1.1_1.js b/test/suite/intl402/ch13/13.1/13.1.1_1.js
new file mode 100644
index 000000000..37be9711b
--- /dev/null
+++ b/test/suite/intl402/ch13/13.1/13.1.1_1.js
@@ -0,0 +1,24 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that localeCompare rejects values that can't be coerced to an object.
+ * @author Norbert Lindenberg
+ */
+
+var invalidValues = [undefined, null];
+
+invalidValues.forEach(function (value) {
+ var error;
+ try {
+ var result = String.prototype.localeCompare.call(value, "");
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("String.prototype.localeCompare did not reject this = " + value + ".");
+ } else if (error.name !== "TypeError") {
+ $ERROR("String.prototype.localeCompare rejected this = " + value + " with wrong error " + error.name + ".");
+ }
+});
+
diff --git a/test/suite/intl402/ch13/13.1/13.1.1_2.js b/test/suite/intl402/ch13/13.1/13.1.1_2.js
new file mode 100644
index 000000000..bad7c0fdd
--- /dev/null
+++ b/test/suite/intl402/ch13/13.1/13.1.1_2.js
@@ -0,0 +1,26 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that localeCompare coerces this to a string.
+ * @author Norbert Lindenberg
+ */
+
+var thisValues = [true, 5, "hello", {toString: function () { return "good bye"; }}];
+var thatValues = ["true", "5", "hello", "good bye"];
+
+var i;
+for (i = 0; i < thisValues.length; i++) {
+ var j;
+ for (j = 0; j < thatValues.length; j++) {
+ var result = String.prototype.localeCompare.call(thisValues[i], thatValues[j]);
+ if ((result === 0) !== (i === j)) {
+ if (result === 0) {
+ $ERROR("localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as equal.");
+ } else {
+ $ERROR("localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as different.");
+ }
+ }
+ }
+}
+
diff --git a/test/suite/intl402/ch13/13.1/13.1.1_3.js b/test/suite/intl402/ch13/13.1/13.1.1_3.js
new file mode 100644
index 000000000..113a2d9aa
--- /dev/null
+++ b/test/suite/intl402/ch13/13.1/13.1.1_3.js
@@ -0,0 +1,26 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that localeCompare coerces that to a string.
+ * @author Norbert Lindenberg
+ */
+
+var thisValues = ["true", "5", "hello", "good bye"];
+var thatValues = [true, 5, "hello", {toString: function () { return "good bye"; }}];
+
+var i;
+for (i = 0; i < thisValues.length; i++) {
+ var j;
+ for (j = 0; j < thatValues.length; j++) {
+ var result = String.prototype.localeCompare.call(thisValues[i], thatValues[j]);
+ if ((result === 0) !== (i === j)) {
+ if (result === 0) {
+ $ERROR("localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as equal.");
+ } else {
+ $ERROR("localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as different.");
+ }
+ }
+ }
+}
+
diff --git a/test/suite/intl402/ch13/13.1/13.1.1_6.js b/test/suite/intl402/ch13/13.1/13.1.1_6.js
new file mode 100644
index 000000000..30607d317
--- /dev/null
+++ b/test/suite/intl402/ch13/13.1/13.1.1_6.js
@@ -0,0 +1,65 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that String.prototype.localeCompare throws the same exceptions as Intl.Collator.
+ * @author Norbert Lindenberg
+ */
+
+var locales = [null, [NaN], ["i"], ["de_DE"]];
+var options = [
+ {localeMatcher: null},
+ {usage: "invalid"},
+ {sensitivity: "invalid"}
+];
+
+locales.forEach(function (locales) {
+ var referenceError, error;
+ try {
+ var collator = new Intl.Collator(locales);
+ } catch (e) {
+ referenceError = e;
+ }
+ if (referenceError === undefined) {
+ $ERROR("Internal error: Expected exception was not thrown by Intl.Collator for locales " + locales + ".");
+ }
+
+ try {
+ var result = "".localeCompare("", locales);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("String.prototype.localeCompare didn't throw exception for locales " + locales + ".");
+ } else if (error.name !== referenceError.name) {
+ $ERROR("String.prototype.localeCompare threw exception " + error.name +
+ " for locales " + locales + "; expected " + referenceError.name + ".");
+ }
+});
+
+options.forEach(function (options) {
+ var referenceError, error;
+ try {
+ var collator = new Intl.Collator([], options);
+ } catch (e) {
+ referenceError = e;
+ }
+ if (referenceError === undefined) {
+ $ERROR("Internal error: Expected exception was not thrown by Intl.Collator for options " +
+ JSON.stringify(options) + ".");
+ }
+
+ try {
+ var result = "".localeCompare("", [], options);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("String.prototype.localeCompare didn't throw exception for options " +
+ JSON.stringify(options) + ".");
+ } else if (error.name !== referenceError.name) {
+ $ERROR("String.prototype.localeCompare threw exception " + error.name +
+ " for options " + JSON.stringify(options) + "; expected " + referenceError.name + ".");
+ }
+});
+
diff --git a/test/suite/intl402/ch13/13.1/13.1.1_7.js b/test/suite/intl402/ch13/13.1/13.1.1_7.js
new file mode 100644
index 000000000..417c5d2e2
--- /dev/null
+++ b/test/suite/intl402/ch13/13.1/13.1.1_7.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 localeCompare produces the same results as Intl.Collator.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+var strings = ["d", "O", "od", "oe", "of", "ö", "o\u0308", "X", "y", "Z", "Z.", "\uD842\uDFB7野家", "吉野家", "!A", "A", "b", "C"];
+var locales = [undefined, ["de"], ["de-u-co-phonebk"], ["en"], ["ja"], ["sv"]];
+var options = [
+ undefined,
+ {usage: "search"},
+ {sensitivity: "base", ignorePunctuation: true}
+];
+
+locales.forEach(function (locales) {
+ options.forEach(function (options) {
+ var referenceCollator = new Intl.Collator(locales, options);
+ var referenceSorted = strings.slice().sort(referenceCollator.compare);
+
+ strings.sort(function (a, b) { return a.localeCompare(b, locales, options); });
+ try {
+ testArraysAreSame(referenceSorted, strings);
+ } catch (e) {
+ e.message += " (Testing with locales " + locales + "; options " + JSON.stringify(options) + ".)";
+ throw e;
+ }
+ });
+});
+
diff --git a/test/suite/intl402/ch13/13.2/13.2.1_1.js b/test/suite/intl402/ch13/13.2/13.2.1_1.js
new file mode 100644
index 000000000..da1ee8fe5
--- /dev/null
+++ b/test/suite/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/test/suite/intl402/ch13/13.2/13.2.1_4.js b/test/suite/intl402/ch13/13.2/13.2.1_4.js
new file mode 100644
index 000000000..e6e0b1163
--- /dev/null
+++ b/test/suite/intl402/ch13/13.2/13.2.1_4.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/test/suite/intl402/ch13/13.2/13.2.1_5.js b/test/suite/intl402/ch13/13.2/13.2.1_5.js
new file mode 100644
index 000000000..eb953b64d
--- /dev/null
+++ b/test/suite/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/test/suite/intl402/ch13/13.3/13.3.0_1.js b/test/suite/intl402/ch13/13.3/13.3.0_1.js
new file mode 100644
index 000000000..0f2902162
--- /dev/null
+++ b/test/suite/intl402/ch13/13.3/13.3.0_1.js
@@ -0,0 +1,32 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that Date.prototype.toLocaleString & Co. handle "this time value" correctly.
+ * @author Norbert Lindenberg
+ */
+
+var functions = {
+ toLocaleString: Date.prototype.toLocaleString,
+ toLocaleDateString: Date.prototype.toLocaleDateString,
+ toLocaleTimeString: Date.prototype.toLocaleTimeString
+};
+var invalidValues = [undefined, null, 5, "5", false, {valueOf: function () { return 5; }}];
+
+Object.getOwnPropertyNames(functions).forEach(function (p) {
+ var f = functions[p];
+ invalidValues.forEach(function (value) {
+ var error;
+ try {
+ var result = f.call(value);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Date.prototype." + p + " did not reject this = " + value + ".");
+ } else if (error.name !== "TypeError") {
+ $ERROR("Date.prototype." + p + " rejected this = " + value + " with wrong error " + error.name + ".");
+ }
+ });
+});
+
diff --git a/test/suite/intl402/ch13/13.3/13.3.0_2.js b/test/suite/intl402/ch13/13.3/13.3.0_2.js
new file mode 100644
index 000000000..7d5f32fa6
--- /dev/null
+++ b/test/suite/intl402/ch13/13.3/13.3.0_2.js
@@ -0,0 +1,26 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that Date.prototype.toLocaleString & Co. handle non-finite values correctly.
+ * @author Norbert Lindenberg
+ */
+
+var functions = {
+ toLocaleString: Date.prototype.toLocaleString,
+ toLocaleDateString: Date.prototype.toLocaleDateString,
+ toLocaleTimeString: Date.prototype.toLocaleTimeString
+};
+var invalidValues = [NaN, Infinity, -Infinity];
+
+Object.getOwnPropertyNames(functions).forEach(function (p) {
+ var f = functions[p];
+ invalidValues.forEach(function (value) {
+ var result = f.call(new Date(value));
+ if (result !== "Invalid Date") {
+ $ERROR("Date.prototype." + p + " did not return \"Invalid Date\" for " +
+ value + " – got " + result + " instead.");
+ }
+ });
+});
+
diff --git a/test/suite/intl402/ch13/13.3/13.3.0_6.js b/test/suite/intl402/ch13/13.3/13.3.0_6.js
new file mode 100644
index 000000000..c97b240b4
--- /dev/null
+++ b/test/suite/intl402/ch13/13.3/13.3.0_6.js
@@ -0,0 +1,74 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that Date.prototype.toLocaleString & Co. throws the same exceptions as Intl.DateTimeFormat.
+ * @author Norbert Lindenberg
+ */
+
+var functions = {
+ toLocaleString: Date.prototype.toLocaleString,
+ toLocaleDateString: Date.prototype.toLocaleDateString,
+ toLocaleTimeString: Date.prototype.toLocaleTimeString
+};
+var locales = [null, [NaN], ["i"], ["de_DE"]];
+var options = [
+ {localeMatcher: null},
+ {timeZone: "invalid"},
+ {hour: "long"},
+ {formatMatcher: "invalid"}
+];
+
+Object.getOwnPropertyNames(functions).forEach(function (p) {
+ var f = functions[p];
+ locales.forEach(function (locales) {
+ var referenceError, error;
+ try {
+ var format = new Intl.DateTimeFormat(locales);
+ } catch (e) {
+ referenceError = e;
+ }
+ if (referenceError === undefined) {
+ $ERROR("Internal error: Expected exception was not thrown by Intl.DateTimeFormat for locales " + locales + ".");
+ }
+
+ try {
+ var result = f.call(new Date(), locales);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Date.prototype." + p + " didn't throw exception for locales " + locales + ".");
+ } else if (error.name !== referenceError.name) {
+ $ERROR("Date.prototype." + p + " threw exception " + error.name +
+ " for locales " + locales + "; expected " + referenceError.name + ".");
+ }
+ });
+
+ options.forEach(function (options) {
+ var referenceError, error;
+ try {
+ var format = new Intl.DateTimeFormat([], options);
+ } catch (e) {
+ referenceError = e;
+ }
+ if (referenceError === undefined) {
+ $ERROR("Internal error: Expected exception was not thrown by Intl.DateTimeFormat for options " +
+ JSON.stringify(options) + ".");
+ }
+
+ try {
+ var result = f.call(new Date(), [], options);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Date.prototype." + p + " didn't throw exception for options " +
+ JSON.stringify(options) + ".");
+ } else if (error.name !== referenceError.name) {
+ $ERROR("Date.prototype." + p + " threw exception " + error.name +
+ " for options " + JSON.stringify(options) + "; expected " + referenceError.name + ".");
+ }
+ });
+});
+
diff --git a/test/suite/intl402/ch13/13.3/13.3.0_7.js b/test/suite/intl402/ch13/13.3/13.3.0_7.js
new file mode 100644
index 000000000..fe7c9271d
--- /dev/null
+++ b/test/suite/intl402/ch13/13.3/13.3.0_7.js
@@ -0,0 +1,58 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that Date.prototype.toLocaleString & Co. produces the same results as Intl.DateTimeFormat.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+var functions = {
+ toLocaleString: [Date.prototype.toLocaleString,
+ {year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric"}],
+ toLocaleDateString: [Date.prototype.toLocaleDateString,
+ {year: "numeric", month: "numeric", day: "numeric"}],
+ toLocaleTimeString: [Date.prototype.toLocaleTimeString,
+ {hour: "numeric", minute: "numeric", second: "numeric"}]
+};
+var dates = [new Date(), new Date(0), new Date(Date.parse("1989-11-09T17:57:00Z"))];
+var locales = [undefined, ["de"], ["th-u-ca-gregory-nu-thai"], ["en"], ["ja-u-ca-japanese"], ["ar-u-ca-islamicc-nu-arab"]];
+var options = [
+ undefined,
+ {hour12: false},
+ {month: "long", day: "numeric", hour: "2-digit", minute: "2-digit"}
+];
+
+Object.getOwnPropertyNames(functions).forEach(function (p) {
+ var f = functions[p][0];
+ var defaults = functions[p][1];
+ locales.forEach(function (locales) {
+ options.forEach(function (options) {
+ var constructorOptions = options;
+ if (options === undefined) {
+ constructorOptions = defaults;
+ } else if (options.day === undefined) {
+ // for simplicity, our options above have either both date and time or neither
+ constructorOptions = Object.create(defaults);
+ for (var prop in options) {
+ if (options.hasOwnProperty(prop)) {
+ constructorOptions[prop] = options[prop];
+ }
+ }
+ }
+ var referenceDateTimeFormat = new Intl.DateTimeFormat(locales, constructorOptions);
+ var referenceFormatted = dates.map(referenceDateTimeFormat.format);
+
+ var formatted = dates.map(function (a) { return f.call(a, locales, options); });
+ try {
+ testArraysAreSame(referenceFormatted, formatted);
+ } catch (e) {
+ e.message += " (Testing with locales " + locales + "; options " +
+ (options ? JSON.stringify(options) : options) + ".)";
+ throw e;
+ }
+ });
+ });
+});
+