summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/ch13/13.1
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/intl402/ch13/13.1')
-rw-r--r--js/src/tests/test262/intl402/ch13/13.1/13.1.1_1.js24
-rw-r--r--js/src/tests/test262/intl402/ch13/13.1/13.1.1_2.js26
-rw-r--r--js/src/tests/test262/intl402/ch13/13.1/13.1.1_3_1.js26
-rw-r--r--js/src/tests/test262/intl402/ch13/13.1/13.1.1_3_2.js22
-rw-r--r--js/src/tests/test262/intl402/ch13/13.1/13.1.1_6_1.js65
-rw-r--r--js/src/tests/test262/intl402/ch13/13.1/13.1.1_6_2.js13
-rw-r--r--js/src/tests/test262/intl402/ch13/13.1/13.1.1_7.js33
-rw-r--r--js/src/tests/test262/intl402/ch13/13.1/13.1.1_L15.js14
-rw-r--r--js/src/tests/test262/intl402/ch13/13.1/browser.js0
-rw-r--r--js/src/tests/test262/intl402/ch13/13.1/shell.js0
10 files changed, 223 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/ch13/13.1/13.1.1_1.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_1.js
new file mode 100644
index 000000000..37be9711b
--- /dev/null
+++ b/js/src/tests/test262/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/js/src/tests/test262/intl402/ch13/13.1/13.1.1_2.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_2.js
new file mode 100644
index 000000000..bad7c0fdd
--- /dev/null
+++ b/js/src/tests/test262/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/js/src/tests/test262/intl402/ch13/13.1/13.1.1_3_1.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_3_1.js
new file mode 100644
index 000000000..113a2d9aa
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_3_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 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/js/src/tests/test262/intl402/ch13/13.1/13.1.1_3_2.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_3_2.js
new file mode 100644
index 000000000..441166c9f
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_3_2.js
@@ -0,0 +1,22 @@
+// Copyright 2013 Mozilla Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/**
+ * @description Tests that String.prototype.localeCompare treats a missing
+ * "that" argument, undefined, and "undefined" as equivalent.
+ * @author Norbert Lindenberg
+ */
+
+var thisValues = ["a", "t", "u", "undefined", "UNDEFINED", "nicht definiert", "xyz", "未定义"];
+
+var i;
+for (i = 0; i < thisValues.length; i++) {
+ var thisValue = thisValues[i];
+ if (thisValue.localeCompare() !== thisValue.localeCompare(undefined)) {
+ $ERROR("String.prototype.localeCompare does not treat missing 'that' argument as undefined.");
+ }
+ if (thisValue.localeCompare(undefined) !== thisValue.localeCompare("undefined")) {
+ $ERROR("String.prototype.localeCompare does not treat undefined 'that' argument as \"undefined\".");
+ }
+}
+
diff --git a/js/src/tests/test262/intl402/ch13/13.1/13.1.1_6_1.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_6_1.js
new file mode 100644
index 000000000..30607d317
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_6_1.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/js/src/tests/test262/intl402/ch13/13.1/13.1.1_6_2.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_6_2.js
new file mode 100644
index 000000000..481a7803b
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_6_2.js
@@ -0,0 +1,13 @@
+// Copyright 2013 Mozilla Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/**
+ * @description Tests that String.prototype.localeCompare uses the standard
+ * built-in Intl.Collator constructor.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+taintDataProperty(Intl, "Collator");
+"a".localeCompare("b");
diff --git a/js/src/tests/test262/intl402/ch13/13.1/13.1.1_7.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_7.js
new file mode 100644
index 000000000..f0c588f64
--- /dev/null
+++ b/js/src/tests/test262/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.", "𠮷野家", "吉野家", "!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/js/src/tests/test262/intl402/ch13/13.1/13.1.1_L15.js b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_L15.js
new file mode 100644
index 000000000..d921de000
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch13/13.1/13.1.1_L15.js
@@ -0,0 +1,14 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/**
+ * @description Tests that String.prototype.localeCompare
+ * meets the requirements for built-in objects defined by the introduction of
+ * chapter 15 of the ECMAScript Language Specification.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testBuiltInObject.js");
+
+testBuiltInObject(String.prototype.localeCompare, true, false, [], 1);
+
diff --git a/js/src/tests/test262/intl402/ch13/13.1/browser.js b/js/src/tests/test262/intl402/ch13/13.1/browser.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch13/13.1/browser.js
diff --git a/js/src/tests/test262/intl402/ch13/13.1/shell.js b/js/src/tests/test262/intl402/ch13/13.1/shell.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch13/13.1/shell.js