aboutsummaryrefslogtreecommitdiffstats
path: root/test/suite/intl402/ch12
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/ch12
parent1af24250750e0a4318ec8efb467245fa0e86c215 (diff)
Added new tests for chapters 10 to 13 of the ECMAScript Internationalization API Specification.
Diffstat (limited to 'test/suite/intl402/ch12')
-rw-r--r--test/suite/intl402/ch12/12.1/12.1.1_1.js43
-rw-r--r--test/suite/intl402/ch12/12.1/12.1.1_18.js12
-rw-r--r--test/suite/intl402/ch12/12.1/12.1.1_22.js18
-rw-r--r--test/suite/intl402/ch12/12.1/12.1.1_23.js14
-rw-r--r--test/suite/intl402/ch12/12.1/12.1.1_25.js12
-rw-r--r--test/suite/intl402/ch12/12.1/12.1.1_5.js18
-rw-r--r--test/suite/intl402/ch12/12.1/12.1.1_6.js12
-rw-r--r--test/suite/intl402/ch12/12.1/12.1.1_TDTO.js107
-rw-r--r--test/suite/intl402/ch12/12.1/12.1.2.js30
-rw-r--r--test/suite/intl402/ch12/12.1/12.1.3.js19
-rw-r--r--test/suite/intl402/ch12/12.2/12.2.1.js22
-rw-r--r--test/suite/intl402/ch12/12.2/12.2.3_b.js47
-rw-r--r--test/suite/intl402/ch12/12.2/12.2.3_c.js52
-rw-r--r--test/suite/intl402/ch12/12.3/12.3.2_1_c.js34
-rw-r--r--test/suite/intl402/ch12/12.3/12.3.2_FDT_1.js26
-rw-r--r--test/suite/intl402/ch12/12.3/12.3.2_TLT_2.js16
-rw-r--r--test/suite/intl402/ch12/12.3/12.3.3.js52
-rw-r--r--test/suite/intl402/ch12/12.3/12.3_a.js (renamed from test/suite/intl402/ch12/12.3/12.3.js)0
-rw-r--r--test/suite/intl402/ch12/12.3/12.3_b.js33
-rw-r--r--test/suite/intl402/ch12/12.4/12.4_a.js15
20 files changed, 582 insertions, 0 deletions
diff --git a/test/suite/intl402/ch12/12.1/12.1.1_1.js b/test/suite/intl402/ch12/12.1/12.1.1_1.js
new file mode 100644
index 000000000..8136fb421
--- /dev/null
+++ b/test/suite/intl402/ch12/12.1/12.1.1_1.js
@@ -0,0 +1,43 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that an object can't be re-initialized as a DateTimeFormat.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+testWithIntlConstructors(function (Constructor) {
+ var obj, error;
+
+ // variant 1: use constructor in a "new" expression
+ obj = new Constructor();
+ try {
+ Intl.DateTimeFormat.call(obj);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Re-initializing object created with \"new\" as DateTimeFormat was not rejected.");
+ } else if (error.name !== "TypeError") {
+ $ERROR("Re-initializing object created with \"new\" as DateTimeFormat was rejected with wrong error " + error.name + ".");
+ }
+
+ // variant 2: use constructor as a function
+ obj = Constructor.call({});
+ error = undefined;
+ try {
+ Intl.DateTimeFormat.call(obj);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Re-initializing object created with constructor as function as DateTimeFormat was not rejected.");
+ } else if (error.name !== "TypeError") {
+ $ERROR("Re-initializing object created with constructor as function as DateTimeFormat was rejected with wrong error " + error.name + ".");
+ }
+
+ return true;
+});
+
diff --git a/test/suite/intl402/ch12/12.1/12.1.1_18.js b/test/suite/intl402/ch12/12.1/12.1.1_18.js
new file mode 100644
index 000000000..e061c0daf
--- /dev/null
+++ b/test/suite/intl402/ch12/12.1/12.1.1_18.js
@@ -0,0 +1,12 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that the option hour12 is processed correctly.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+testOption(Intl.DateTimeFormat, "hour12", "boolean");
+
diff --git a/test/suite/intl402/ch12/12.1/12.1.1_22.js b/test/suite/intl402/ch12/12.1/12.1.1_22.js
new file mode 100644
index 000000000..5c317c6b9
--- /dev/null
+++ b/test/suite/intl402/ch12/12.1/12.1.1_22.js
@@ -0,0 +1,18 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that the behavior of a Record is not affected by adversarial
+ * changes to Object.prototype.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+taintProperties(["weekday", "era", "year", "month", "day", "hour", "minute", "second", "timeZone"]);
+
+var locale = new Intl.DateTimeFormat(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale;
+if (!isCanonicalizedStructurallyValidLanguageTag(locale)) {
+ $ERROR("DateTimeFormat returns invalid locale " + locale + ".");
+}
+
diff --git a/test/suite/intl402/ch12/12.1/12.1.1_23.js b/test/suite/intl402/ch12/12.1/12.1.1_23.js
new file mode 100644
index 000000000..d26e1d28c
--- /dev/null
+++ b/test/suite/intl402/ch12/12.1/12.1.1_23.js
@@ -0,0 +1,14 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that the options for the date and time components are processed correctly.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+getDateTimeComponents().forEach(function (component) {
+ testOption(Intl.DateTimeFormat, component, "string", getDateTimeComponentValues(component), undefined, {isILD: true});
+});
+
diff --git a/test/suite/intl402/ch12/12.1/12.1.1_25.js b/test/suite/intl402/ch12/12.1/12.1.1_25.js
new file mode 100644
index 000000000..ccaf7be03
--- /dev/null
+++ b/test/suite/intl402/ch12/12.1/12.1.1_25.js
@@ -0,0 +1,12 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that the option formatMatcher is processed correctly.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+testOption(Intl.DateTimeFormat, "formatMatcher", "string", ["basic", "best fit"], "best fit", {noReturn: true});
+
diff --git a/test/suite/intl402/ch12/12.1/12.1.1_5.js b/test/suite/intl402/ch12/12.1/12.1.1_5.js
new file mode 100644
index 000000000..c6b166814
--- /dev/null
+++ b/test/suite/intl402/ch12/12.1/12.1.1_5.js
@@ -0,0 +1,18 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that the behavior of a Record is not affected by adversarial
+ * changes to Object.prototype.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+taintProperties(["localeMatcher"]);
+
+var locale = new Intl.DateTimeFormat(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale;
+if (!isCanonicalizedStructurallyValidLanguageTag(locale)) {
+ $ERROR("DateTimeFormat returns invalid locale " + locale + ".");
+}
+
diff --git a/test/suite/intl402/ch12/12.1/12.1.1_6.js b/test/suite/intl402/ch12/12.1/12.1.1_6.js
new file mode 100644
index 000000000..148ca02f6
--- /dev/null
+++ b/test/suite/intl402/ch12/12.1/12.1.1_6.js
@@ -0,0 +1,12 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that the option localeMatcher is processed correctly.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+testOption(Intl.DateTimeFormat, "localeMatcher", "string", ["lookup", "best fit"], "best fit", {noReturn: true});
+
diff --git a/test/suite/intl402/ch12/12.1/12.1.1_TDTO.js b/test/suite/intl402/ch12/12.1/12.1.1_TDTO.js
new file mode 100644
index 000000000..5df6a1cf2
--- /dev/null
+++ b/test/suite/intl402/ch12/12.1/12.1.1_TDTO.js
@@ -0,0 +1,107 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that the set of options for the date and time components is processed correctly.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+var locales = [[], ["zh-Hans-CN"], ["hi-IN"], ["en-US"], ["id-ID"]];
+var dates = [new Date(), new Date(0), new Date(Date.parse("1989-11-09T17:57:00Z"))];
+
+function testWithDateTimeFormat(options, expected) {
+ locales.forEach(function (locales) {
+ var format = new Intl.DateTimeFormat(locales, options);
+ var resolvedOptions = format.resolvedOptions();
+ getDateTimeComponents().forEach(function (component) {
+ if (resolvedOptions.hasOwnProperty(component)) {
+ if (!expected.hasOwnProperty(component)) {
+ $ERROR("Unrequested component " + component +
+ " added to expected subset " + JSON.stringify(expected) +
+ "; locales " + locales + ", options " +
+ (options ? JSON.stringify(options) : options) + ".");
+ }
+ } else {
+ if (expected.hasOwnProperty(component)) {
+ $ERROR("Missing component " + component +
+ " from expected subset " + JSON.stringify(expected) +
+ "; locales " + locales + ", options " +
+ (options ? JSON.stringify(options) : options) + ".");
+ }
+ }
+ });
+ });
+}
+
+function testWithToLocale(f, options, expected) {
+ // expected can be either one subset or an array of possible subsets
+ if (expected.length === undefined) {
+ expected = [expected];
+ }
+ locales.forEach(function (locales) {
+ dates.forEach(function (date) {
+ var formatted = Date.prototype[f].call(date, locales, options);
+ var expectedStrings = [];
+ expected.forEach(function (expected) {
+ var referenceFormat = new Intl.DateTimeFormat(locales, expected);
+ expectedStrings.push(referenceFormat.format(date));
+ });
+ if (expectedStrings.indexOf(formatted) === -1) {
+ $ERROR("Function " + f + " did not return expected string for locales " +
+ locales + ", options " + (options? JSON.stringify(options) : options) +
+ "; expected " +
+ (expectedStrings.length === 1 ? expectedStrings[0] : "one of " + expectedStrings) +
+ ", got " + formatted + ".");
+ }
+ });
+ });
+}
+
+// any/date: steps 5a, 6a, 7a
+testWithDateTimeFormat(undefined, {year: "numeric", month: "numeric", day: "numeric"});
+
+// any/date: steps 5a, 6a
+testWithDateTimeFormat({year: "numeric", month: "numeric"}, {year: "numeric", month: "numeric"});
+
+// any/date: steps 5a, 6a
+testWithDateTimeFormat({hour: "numeric", minute: "numeric"}, {hour: "numeric", minute: "numeric"});
+
+// any/all: steps 5a, 6a, 7a, 8a
+testWithToLocale("toLocaleString", undefined, [
+ // the first one is not guaranteed to be supported; the second one is
+ {year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric"},
+ {weekday: "short", year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric"}
+]);
+
+// any/all: steps 5a, 6a
+testWithToLocale("toLocaleString", {year: "numeric", month: "numeric"}, {year: "numeric", month: "numeric"});
+
+// any/all: steps 5a, 6a
+testWithToLocale("toLocaleString", {hour: "numeric", minute: "numeric"}, {hour: "numeric", minute: "numeric"});
+
+// date/date: steps 5a, 7a
+testWithToLocale("toLocaleDateString", undefined, {year: "numeric", month: "numeric", day: "numeric"});
+
+// date/date: steps 5a
+testWithToLocale("toLocaleDateString", {year: "numeric", month: "numeric"}, {year: "numeric", month: "numeric"});
+
+// date/date: steps 5a, 7a
+testWithToLocale("toLocaleDateString", {hour: "numeric", minute: "numeric", second: "numeric"}, [
+ // the first one is not guaranteed to be supported; the second one is
+ {year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric"},
+ {weekday: "short", year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric"}
+]);
+
+// time/time: steps 6a, 8a
+testWithToLocale("toLocaleTimeString", undefined, {hour: "numeric", minute: "numeric", second: "numeric"});
+
+// time/time: steps 6a, 8a
+testWithToLocale("toLocaleTimeString", {weekday: "short", year: "numeric", month: "numeric", day: "numeric"},
+ {weekday: "short", year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric"});
+
+// time/time: steps 6a
+testWithToLocale("toLocaleTimeString", {hour: "numeric", minute: "numeric"}, {hour: "numeric", minute: "numeric"});
+
+
diff --git a/test/suite/intl402/ch12/12.1/12.1.2.js b/test/suite/intl402/ch12/12.1/12.1.2.js
new file mode 100644
index 000000000..3ffed2ec8
--- /dev/null
+++ b/test/suite/intl402/ch12/12.1/12.1.2.js
@@ -0,0 +1,30 @@
+// 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 Intl.DateTimeFormat can be subclassed.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+// get a date-time format and have it format an array of dates for comparison with the subclass
+var locales = ["tlh", "id", "en"];
+var a = [new Date(0), Date.now(), new Date(Date.parse("1989-11-09T17:57:00Z"))];
+var referenceDateTimeFormat = new Intl.DateTimeFormat(locales);
+var referenceFormatted = a.map(referenceDateTimeFormat.format);
+
+function MyDateTimeFormat(locales, options) {
+ Intl.DateTimeFormat.call(this, locales, options);
+ // could initialize MyDateTimeFormat properties
+}
+
+MyDateTimeFormat.prototype = Object.create(Intl.DateTimeFormat.prototype);
+MyDateTimeFormat.prototype.constructor = MyDateTimeFormat;
+// could add methods to MyDateTimeFormat.prototype
+
+var format = new MyDateTimeFormat(locales);
+var actual = a.map(format.format);
+testArraysAreSame(referenceFormatted, actual);
+
diff --git a/test/suite/intl402/ch12/12.1/12.1.3.js b/test/suite/intl402/ch12/12.1/12.1.3.js
new file mode 100644
index 000000000..5e70bbb8f
--- /dev/null
+++ b/test/suite/intl402/ch12/12.1/12.1.3.js
@@ -0,0 +1,19 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that objects constructed by Intl.DateTimeFormat have the specified internal properties.
+ * @author Norbert Lindenberg
+ */
+
+var obj = new Intl.DateTimeFormat();
+
+var actualPrototype = Object.getPrototypeOf(obj);
+if (actualPrototype !== Intl.DateTimeFormat.prototype) {
+ $ERROR("Prototype of object constructed by Intl.DateTimeFormat isn't Intl.DateTimeFormat.prototype; got " + actualPrototype);
+}
+
+if (!Object.isExtensible(obj)) {
+ $ERROR("Object constructed by Intl.DateTimeFormat must be extensible.");
+}
+
diff --git a/test/suite/intl402/ch12/12.2/12.2.1.js b/test/suite/intl402/ch12/12.2/12.2.1.js
new file mode 100644
index 000000000..3590c0a9d
--- /dev/null
+++ b/test/suite/intl402/ch12/12.2/12.2.1.js
@@ -0,0 +1,22 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/**
+ * @description Tests that Intl.DateTimeFormat.prototype has the required attributes.
+ * @author Norbert Lindenberg
+ */
+
+var desc = Object.getOwnPropertyDescriptor(Intl.DateTimeFormat, "prototype");
+if (desc === undefined) {
+ $ERROR("Intl.DateTimeFormat.prototype is not defined.");
+}
+if (desc.writable) {
+ $ERROR("Intl.DateTimeFormat.prototype must not be writable.");
+}
+if (desc.enumerable) {
+ $ERROR("Intl.DateTimeFormat.prototype must not be enumerable.");
+}
+if (desc.configurable) {
+ $ERROR("Intl.DateTimeFormat.prototype must not be configurable.");
+}
+
diff --git a/test/suite/intl402/ch12/12.2/12.2.3_b.js b/test/suite/intl402/ch12/12.2/12.2.3_b.js
new file mode 100644
index 000000000..65fd9dc5f
--- /dev/null
+++ b/test/suite/intl402/ch12/12.2/12.2.3_b.js
@@ -0,0 +1,47 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/**
+ * @description Tests that Intl.DateTimeFormat does not accept Unicode locale
+ * extension keys and values that are not allowed.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+var locales = ["ja-JP", "zh-Hans-CN", "zh-Hant-TW"];
+var input = new Date(Date.parse("1989-11-09T17:57:00Z"));
+
+locales.forEach(function (locale) {
+ var defaultDateTimeFormat = new Intl.DateTimeFormat([locale]);
+ var defaultOptions = defaultDateTimeFormat.resolvedOptions();
+ var defaultOptionsJSON = JSON.stringify(defaultOptions);
+ var defaultLocale = defaultOptions.locale;
+ var defaultFormatted = defaultDateTimeFormat.format(input);
+
+ var keyValues = {
+ "cu": ["USD", "EUR", "JPY", "CNY", "TWD", "invalid"], // DateTimeFormat internally uses NumberFormat
+ "nu": ["native", "traditio", "finance", "invalid"],
+ "tz": ["usnavajo", "utcw01", "aumel", "uslax", "usnyc", "deber", "invalid"]
+ };
+
+ Object.getOwnPropertyNames(keyValues).forEach(function (key) {
+ keyValues[key].forEach(function (value) {
+ var dateTimeFormat = new Intl.DateTimeFormat([locale + "-u-" + key + "-" + value]);
+ var options = dateTimeFormat.resolvedOptions();
+ if (options.locale !== defaultLocale) {
+ $ERROR("Locale " + options.locale + " is affected by key " +
+ key + "; value " + value + ".");
+ }
+ if (JSON.stringify(options) !== defaultOptionsJSON) {
+ $ERROR("Resolved options " + JSON.stringify(options) + " are affected by key " +
+ key + "; value " + value + ".");
+ }
+ if (defaultFormatted !== dateTimeFormat.format(input)) {
+ $ERROR("Formatted value " + dateTimeFormat.format(input) + " is affected by key " +
+ key + "; value " + value + ".");
+ }
+ });
+ });
+});
+
diff --git a/test/suite/intl402/ch12/12.2/12.2.3_c.js b/test/suite/intl402/ch12/12.2/12.2.3_c.js
new file mode 100644
index 000000000..0aced6ca9
--- /dev/null
+++ b/test/suite/intl402/ch12/12.2/12.2.3_c.js
@@ -0,0 +1,52 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/**
+ * @description Tests that Intl.DateTimeFormat provides the required date-time
+ * format component subsets.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+var locales = ["de-DE", "en-US", "hi-IN", "id-ID", "ja-JP", "th-TH", "zh-Hans-CN", "zh-Hant-TW", "zxx"];
+var subsets = [
+ {weekday: "long", year: "numeric", month: "numeric", day: "numeric",
+ hour: "numeric", minute: "numeric", second: "numeric"},
+ {weekday: "long", year: "numeric", month: "numeric", day: "numeric"},
+ {year: "numeric", month: "numeric", day: "numeric"},
+ {year: "numeric", month: "numeric"},
+ {month: "numeric", day: "numeric"},
+ {hour: "numeric", minute: "numeric", second: "numeric"},
+ {hour: "numeric", minute: "numeric"}
+];
+
+locales.forEach(function (locale) {
+ subsets.forEach(function (subset) {
+ var format = new Intl.DateTimeFormat([locale], subset);
+ var actual = format.resolvedOptions();
+ getDateTimeComponents().forEach(function (component) {
+ if (actual.hasOwnProperty(component)) {
+ if (!subset.hasOwnProperty(component)) {
+ $ERROR("Unrequested component " + component +
+ " added to requested subset " + JSON.stringify(subset) +
+ "; locale " + locale + ".");
+ }
+ try {
+ testValidDateTimeComponentValue(component, actual[component]);
+ } catch (e) {
+ e.message += " (Testing locale " + locale + "; subset " +
+ JSON.stringify(subset) + ")";
+ throw e;
+ }
+ } else {
+ if (subset.hasOwnProperty(component)) {
+ $ERROR("Missing component " + component +
+ " from requested subset " + JSON.stringify(subset) +
+ "; locale " + locale + ".");
+ }
+ }
+ });
+ });
+});
+
diff --git a/test/suite/intl402/ch12/12.3/12.3.2_1_c.js b/test/suite/intl402/ch12/12.3/12.3.2_1_c.js
new file mode 100644
index 000000000..d4b9f891f
--- /dev/null
+++ b/test/suite/intl402/ch12/12.3/12.3.2_1_c.js
@@ -0,0 +1,34 @@
+// 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.DateTimeFormat.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+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"}
+];
+
+locales.forEach(function (locales) {
+ options.forEach(function (options) {
+ var formatObj = new Intl.DateTimeFormat(locales, options);
+ var formatFunc = formatObj.format;
+ dates.forEach(function (date) {
+ var referenceFormatted = formatObj.format(date);
+ var formatted = formatFunc(date);
+ 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/ch12/12.3/12.3.2_FDT_1.js b/test/suite/intl402/ch12/12.3/12.3.2_FDT_1.js
new file mode 100644
index 000000000..d643d7928
--- /dev/null
+++ b/test/suite/intl402/ch12/12.3/12.3.2_FDT_1.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 format handles non-finite values correctly.
+ * @author Norbert Lindenberg
+ */
+
+var invalidValues = [NaN, Infinity, -Infinity];
+
+var format = new Intl.DateTimeFormat();
+
+invalidValues.forEach(function (value) {
+ var error;
+ try {
+ var result = format.format(value);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Invalid value " + value + " was not rejected.");
+ } else if (error.name !== "RangeError") {
+ $ERROR("Invalid value " + value + " was rejected with wrong error " + error.name + ".");
+ }
+});
+
diff --git a/test/suite/intl402/ch12/12.3/12.3.2_TLT_2.js b/test/suite/intl402/ch12/12.3/12.3.2_TLT_2.js
new file mode 100644
index 000000000..bf0a8ed36
--- /dev/null
+++ b/test/suite/intl402/ch12/12.3/12.3.2_TLT_2.js
@@ -0,0 +1,16 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that the behavior of a Record is not affected by adversarial
+ * changes to Object.prototype.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+taintProperties(["weekday", "era", "year", "month", "day", "hour", "minute", "second", "inDST"]);
+
+var format = new Intl.DateTimeFormat();
+var time = format.format();
+
diff --git a/test/suite/intl402/ch12/12.3/12.3.3.js b/test/suite/intl402/ch12/12.3/12.3.3.js
new file mode 100644
index 000000000..f5a9f688a
--- /dev/null
+++ b/test/suite/intl402/ch12/12.3/12.3.3.js
@@ -0,0 +1,52 @@
+// 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.DateTimeFormat.prototype.resolvedOptions
+ * has the right properties.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+var actual = new Intl.DateTimeFormat().resolvedOptions();
+
+var actual2 = new Intl.DateTimeFormat().resolvedOptions();
+if (actual2 === actual) {
+ $ERROR("resolvedOptions returned the same object twice.");
+}
+
+// source: CLDR file common/bcp47/calendar.xml; version CLDR 21.
+var calendars = [
+ "buddhist",
+ "chinese",
+ "coptic",
+ "ethioaa",
+ "ethiopic",
+ "gregory",
+ "hebrew",
+ "indian",
+ "islamic",
+ "islamicc",
+ "iso8601",
+ "japanese",
+ "persian",
+ "roc"
+];
+
+// this assumes the default values where the specification provides them
+mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag);
+mustHaveProperty(actual, "calendar", calendars);
+mustHaveProperty(actual, "numberingSystem", isValidNumberingSystem);
+mustHaveProperty(actual, "timeZone", [undefined]);
+mustHaveProperty(actual, "hour12", [true, false]);
+mustNotHaveProperty(actual, "weekday");
+mustNotHaveProperty(actual, "era");
+mustHaveProperty(actual, "year", ["2-digit", "numeric"]);
+mustHaveProperty(actual, "month", ["2-digit", "numeric", "narrow", "short", "long"]);
+mustHaveProperty(actual, "day", ["2-digit", "numeric"]);
+mustNotHaveProperty(actual, "hour");
+mustNotHaveProperty(actual, "minute");
+mustNotHaveProperty(actual, "second");
+mustNotHaveProperty(actual, "timeZoneName");
+
diff --git a/test/suite/intl402/ch12/12.3/12.3.js b/test/suite/intl402/ch12/12.3/12.3_a.js
index e1d795b91..e1d795b91 100644
--- a/test/suite/intl402/ch12/12.3/12.3.js
+++ b/test/suite/intl402/ch12/12.3/12.3_a.js
diff --git a/test/suite/intl402/ch12/12.3/12.3_b.js b/test/suite/intl402/ch12/12.3/12.3_b.js
new file mode 100644
index 000000000..d905bf571
--- /dev/null
+++ b/test/suite/intl402/ch12/12.3/12.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.DateTimeFormat.prototype functions throw a
+ * TypeError if called on a non-object value or an object that hasn't been
+ * initialized as a DateTimeFormat.
+ * @author Norbert Lindenberg
+ */
+
+var functions = {
+ "format getter": Object.getOwnPropertyDescriptor(Intl.DateTimeFormat.prototype, "format").get,
+ resolvedOptions: Intl.DateTimeFormat.prototype.resolvedOptions
+};
+var invalidTargets = [undefined, null, true, 0, "DateTimeFormat", [], {}];
+
+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 + ".");
+ }
+ });
+});
+
diff --git a/test/suite/intl402/ch12/12.4/12.4_a.js b/test/suite/intl402/ch12/12.4/12.4_a.js
new file mode 100644
index 000000000..8e8d5954c
--- /dev/null
+++ b/test/suite/intl402/ch12/12.4/12.4_a.js
@@ -0,0 +1,15 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that Intl.DateTimeFormat instances have the specified properties.
+ * @author Norbert Lindenberg
+ */
+
+var obj = new Intl.DateTimeFormat();
+
+var toStringValue = Object.prototype.toString.call(obj);
+if (toStringValue !== "[object Object]") {
+ $ERROR("Intl.DateTimeFormat instance produces wrong [[Class]] - toString returns " + toStringValue + ".");
+}
+