summaryrefslogtreecommitdiff
path: root/test/suite/intl402/ch12/12.1
diff options
context:
space:
mode:
Diffstat (limited to 'test/suite/intl402/ch12/12.1')
-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
10 files changed, 285 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.");
+}
+