aboutsummaryrefslogtreecommitdiffstats
path: root/test/suite/intl402/ch10/10.1
diff options
context:
space:
mode:
Diffstat (limited to 'test/suite/intl402/ch10/10.1')
-rw-r--r--test/suite/intl402/ch10/10.1/10.1.1_1.js43
-rw-r--r--test/suite/intl402/ch10/10.1/10.1.1_10.js18
-rw-r--r--test/suite/intl402/ch10/10.1/10.1.1_11.js12
-rw-r--r--test/suite/intl402/ch10/10.1/10.1.1_13.js14
-rw-r--r--test/suite/intl402/ch10/10.1/10.1.1_19_b.js44
-rw-r--r--test/suite/intl402/ch10/10.1/10.1.1_19_c.js64
-rw-r--r--test/suite/intl402/ch10/10.1/10.1.1_20.js13
-rw-r--r--test/suite/intl402/ch10/10.1/10.1.1_23.js13
-rw-r--r--test/suite/intl402/ch10/10.1/10.1.1_6.js12
-rw-r--r--test/suite/intl402/ch10/10.1/10.1.2_a.js30
-rw-r--r--test/suite/intl402/ch10/10.1/10.1.3.js19
11 files changed, 282 insertions, 0 deletions
diff --git a/test/suite/intl402/ch10/10.1/10.1.1_1.js b/test/suite/intl402/ch10/10.1/10.1.1_1.js
new file mode 100644
index 000000000..432e073fc
--- /dev/null
+++ b/test/suite/intl402/ch10/10.1/10.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 Collator.
+ * @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.Collator.call(obj);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Re-initializing object created with \"new\" as Collator was not rejected.");
+ } else if (error.name !== "TypeError") {
+ $ERROR("Re-initializing object created with \"new\" as Collator was rejected with wrong error " + error.name + ".");
+ }
+
+ // variant 2: use constructor as a function
+ obj = Constructor.call({});
+ error = undefined;
+ try {
+ Intl.Collator.call(obj);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Re-initializing object created with constructor as function as Collator was not rejected.");
+ } else if (error.name !== "TypeError") {
+ $ERROR("Re-initializing object created with constructor as function as Collator was rejected with wrong error " + error.name + ".");
+ }
+
+ return true;
+});
+
diff --git a/test/suite/intl402/ch10/10.1/10.1.1_10.js b/test/suite/intl402/ch10/10.1/10.1.1_10.js
new file mode 100644
index 000000000..dd4981264
--- /dev/null
+++ b/test/suite/intl402/ch10/10.1/10.1.1_10.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", "kn", "kk", "kf"]);
+
+var locale = new Intl.Collator(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale;
+if (!isCanonicalizedStructurallyValidLanguageTag(locale)) {
+ $ERROR("Collator returns invalid locale " + locale + ".");
+}
+
diff --git a/test/suite/intl402/ch10/10.1/10.1.1_11.js b/test/suite/intl402/ch10/10.1/10.1.1_11.js
new file mode 100644
index 000000000..447fd8b28
--- /dev/null
+++ b/test/suite/intl402/ch10/10.1/10.1.1_11.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.Collator, "localeMatcher", "string", ["lookup", "best fit"], "best fit", {noReturn: true});
+
diff --git a/test/suite/intl402/ch10/10.1/10.1.1_13.js b/test/suite/intl402/ch10/10.1/10.1.1_13.js
new file mode 100644
index 000000000..b0f1bbc8e
--- /dev/null
+++ b/test/suite/intl402/ch10/10.1/10.1.1_13.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 numeric, normalization, and caseFirst are processed correctly.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+testOption(Intl.Collator, "numeric", "boolean", undefined, undefined, {isOptional: true});
+testOption(Intl.Collator, "normalization", "boolean", undefined, undefined, {isOptional: true});
+testOption(Intl.Collator, "caseFirst", "string", ["upper", "lower", "false"], undefined, {isOptional: true});
+
diff --git a/test/suite/intl402/ch10/10.1/10.1.1_19_b.js b/test/suite/intl402/ch10/10.1/10.1.1_19_b.js
new file mode 100644
index 000000000..f1fef2704
--- /dev/null
+++ b/test/suite/intl402/ch10/10.1/10.1.1_19_b.js
@@ -0,0 +1,44 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests the special handling of the "co" key in Intl.Collator.
+ * @author Norbert Lindenberg
+ */
+
+function checkCollation(extensionCoValue, usageValue, expectedCollations, expectedUsage) {
+ var requestLocale = extensionCoValue !== undefined ? "de-DE-u-co-" + extensionCoValue : "de-DE";
+ var options = usageValue !== undefined ? { usage: usageValue } : undefined;
+ var collator = new Intl.Collator([requestLocale], options);
+
+ var collation = collator.resolvedOptions().collation;
+ if (expectedCollations.indexOf(collation) === -1) {
+ $ERROR((extensionCoValue === undefined ? "Default collation" : "Collation for \"" + extensionCoValue) +
+ "\" should be " + expectedCollations.join(" or ") + ", but is " + collation + ".");
+ }
+
+ var usage = collator.resolvedOptions().usage;
+ if (expectedUsage !== usage) {
+ $ERROR((usageValue === undefined ? "Default usage" : "Usage") +
+ " should be " + expectedUsage + ", but is " + usage + ".");
+ }
+}
+
+checkCollation(undefined, undefined, ["default"], "sort");
+
+checkCollation("phonebk", undefined, ["phonebk", "default"], "sort");
+
+checkCollation("invalid", undefined, ["default"], "sort");
+
+checkCollation("standard", undefined, ["default"], "sort");
+
+checkCollation("standard", "search", ["default"], "search");
+
+checkCollation("standard", "sort", ["default"], "sort");
+
+checkCollation("search", undefined, ["default"], "sort");
+
+checkCollation("search", "search", ["default"], "search");
+
+checkCollation("search", "sort", ["default"], "sort");
+
diff --git a/test/suite/intl402/ch10/10.1/10.1.1_19_c.js b/test/suite/intl402/ch10/10.1/10.1.1_19_c.js
new file mode 100644
index 000000000..577ef5600
--- /dev/null
+++ b/test/suite/intl402/ch10/10.1/10.1.1_19_c.js
@@ -0,0 +1,64 @@
+// 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 numeric, normalization, and caseFirst can be
+ * set through either the locale or the options.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+var options = [
+ {key: "kn", property: "numeric", type: "boolean", values: [true, false]},
+ {key: "kk", property: "normalization", type: "boolean", values: [true, false]},
+ {key: "kf", property: "caseFirst", type: "string", values: ["upper", "lower", "false"]}
+];
+
+options.forEach(function (option) {
+ var defaultLocale = new Intl.Collator().resolvedOptions().locale;
+ var collator, opt, result;
+
+ // find out which values are supported for a property in the default locale
+ var supportedValues = [];
+ option.values.forEach(function (value) {
+ opt = {};
+ opt[option.property] = value;
+ collator = new Intl.Collator([defaultLocale], opt);
+ result = collator.resolvedOptions()[option.property];
+ if (result !== undefined && supportedValues.indexOf(result) === -1) {
+ supportedValues.push(result);
+ }
+ });
+
+ // verify that the supported values can also be set through the locale
+ supportedValues.forEach(function (value) {
+ collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + value]);
+ result = collator.resolvedOptions()[option.property];
+ if (result !== value) {
+ $ERROR("Property " + option.property + " couldn't be set through locale extension key " +
+ option.key + "; requested value: " + value + "; actual value: " + result + ".");
+ }
+ });
+
+ // verify that the options setting overrides the locale setting
+ supportedValues.forEach(function (value) {
+ var otherValue;
+ option.values.forEach(function (possibleValue) {
+ if (possibleValue !== value) {
+ otherValue = possibleValue;
+ }
+ });
+ if (otherValue !== undefined) {
+ opt = {};
+ opt[option.property] = value;
+ collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + otherValue], opt);
+ result = collator.resolvedOptions()[option.property];
+ if (result !== value) {
+ $ERROR("Options value for property " + option.property + " doesn't override locale extension key " +
+ option.key + "; requested value: " + value + "; actual value: " + result + ".");
+ }
+ }
+ });
+});
+
diff --git a/test/suite/intl402/ch10/10.1/10.1.1_20.js b/test/suite/intl402/ch10/10.1/10.1.1_20.js
new file mode 100644
index 000000000..97d70c0f9
--- /dev/null
+++ b/test/suite/intl402/ch10/10.1/10.1.1_20.js
@@ -0,0 +1,13 @@
+// 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 sensitivity is processed correctly.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+// the fallback is variant only for usage === sort, but that happens to be the fallback for usage
+testOption(Intl.Collator, "sensitivity", "string", ["base", "accent", "case", "variant"], "variant");
+
diff --git a/test/suite/intl402/ch10/10.1/10.1.1_23.js b/test/suite/intl402/ch10/10.1/10.1.1_23.js
new file mode 100644
index 000000000..0b5261509
--- /dev/null
+++ b/test/suite/intl402/ch10/10.1/10.1.1_23.js
@@ -0,0 +1,13 @@
+// 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 ignorePunctuation is processed correctly.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+// the fallback is variant only for usage === sort, but that happens to be the fallback for usage
+testOption(Intl.Collator, "ignorePunctuation", "boolean", undefined, false);
+
diff --git a/test/suite/intl402/ch10/10.1/10.1.1_6.js b/test/suite/intl402/ch10/10.1/10.1.1_6.js
new file mode 100644
index 000000000..bc13436d7
--- /dev/null
+++ b/test/suite/intl402/ch10/10.1/10.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 usage is processed correctly.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+testOption(Intl.Collator, "usage", "string", ["sort", "search"], "sort");
+
diff --git a/test/suite/intl402/ch10/10.1/10.1.2_a.js b/test/suite/intl402/ch10/10.1/10.1.2_a.js
new file mode 100644
index 000000000..de69a4809
--- /dev/null
+++ b/test/suite/intl402/ch10/10.1/10.1.2_a.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.Collator can be subclassed.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+// get a collator and have it sort an array for comparison with the subclass
+var locales = ["tlh", "id", "en"];
+var a = ["A", "C", "E", "B", "D", "F"];
+var referenceCollator = new Intl.Collator(locales);
+var referenceSorted = a.slice().sort(referenceCollator.compare);
+
+function MyCollator(locales, options) {
+ Intl.Collator.call(this, locales, options);
+ // could initialize MyCollator properties
+}
+
+MyCollator.prototype = Object.create(Intl.Collator.prototype);
+MyCollator.prototype.constructor = MyCollator;
+// could add methods to MyCollator.prototype
+
+var collator = new MyCollator(locales);
+a.sort(collator.compare);
+testArraysAreSame(referenceSorted, a);
+
diff --git a/test/suite/intl402/ch10/10.1/10.1.3.js b/test/suite/intl402/ch10/10.1/10.1.3.js
new file mode 100644
index 000000000..7459d98d6
--- /dev/null
+++ b/test/suite/intl402/ch10/10.1/10.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.Collator have the specified internal properties.
+ * @author Norbert Lindenberg
+ */
+
+var obj = new Intl.Collator();
+
+var actualPrototype = Object.getPrototypeOf(obj);
+if (actualPrototype !== Intl.Collator.prototype) {
+ $ERROR("Prototype of object constructed by Intl.Collator isn't Intl.Collator.prototype; got " + actualPrototype);
+}
+
+if (!Object.isExtensible(obj)) {
+ $ERROR("Object constructed by Intl.Collator must be extensible.");
+}
+