summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/String/prototype/localeCompare
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/intl402/String/prototype/localeCompare')
-rw-r--r--js/src/tests/test262/intl402/String/prototype/localeCompare/browser.js0
-rw-r--r--js/src/tests/test262/intl402/String/prototype/localeCompare/builtin.js30
-rw-r--r--js/src/tests/test262/intl402/String/prototype/localeCompare/default-options-object-prototype.js21
-rw-r--r--js/src/tests/test262/intl402/String/prototype/localeCompare/length.js34
-rw-r--r--js/src/tests/test262/intl402/String/prototype/localeCompare/missing-arguments-coerced-to-undefined.js21
-rw-r--r--js/src/tests/test262/intl402/String/prototype/localeCompare/return-abrupt-this-value.js20
-rw-r--r--js/src/tests/test262/intl402/String/prototype/localeCompare/returns-same-results-as-Collator.js32
-rw-r--r--js/src/tests/test262/intl402/String/prototype/localeCompare/shell.js24
-rw-r--r--js/src/tests/test262/intl402/String/prototype/localeCompare/taint-Intl-Collator.js16
-rw-r--r--js/src/tests/test262/intl402/String/prototype/localeCompare/that-arg-coerced-to-string.js22
-rw-r--r--js/src/tests/test262/intl402/String/prototype/localeCompare/this-value-coerced-to-string.js22
-rw-r--r--js/src/tests/test262/intl402/String/prototype/localeCompare/throws-same-exceptions-as-Collator.js47
12 files changed, 289 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/String/prototype/localeCompare/browser.js b/js/src/tests/test262/intl402/String/prototype/localeCompare/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/intl402/String/prototype/localeCompare/browser.js
diff --git a/js/src/tests/test262/intl402/String/prototype/localeCompare/builtin.js b/js/src/tests/test262/intl402/String/prototype/localeCompare/builtin.js
new file mode 100644
index 0000000000..ea9820bab9
--- /dev/null
+++ b/js/src/tests/test262/intl402/String/prototype/localeCompare/builtin.js
@@ -0,0 +1,30 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/*---
+es5id: 13.1.1_L15
+description: >
+ Tests that String.prototype.localeCompare meets the requirements
+ for built-in objects defined by the introduction of chapter 17 of
+ the ECMAScript Language Specification.
+author: Norbert Lindenberg
+includes: [isConstructor.js]
+features: [Reflect.construct]
+---*/
+
+assert.sameValue(Object.prototype.toString.call(String.prototype.localeCompare), "[object Function]",
+ "The [[Class]] internal property of a built-in function must be " +
+ "\"Function\".");
+
+assert(Object.isExtensible(String.prototype.localeCompare),
+ "Built-in objects must be extensible.");
+
+assert.sameValue(Object.getPrototypeOf(String.prototype.localeCompare), Function.prototype);
+
+assert.sameValue(String.prototype.localeCompare.hasOwnProperty("prototype"), false,
+ "Built-in functions that aren't constructors must not have a prototype property.");
+
+assert.sameValue(isConstructor(String.prototype.localeCompare), false,
+ "Built-in functions don't implement [[Construct]] unless explicitly specified.");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/String/prototype/localeCompare/default-options-object-prototype.js b/js/src/tests/test262/intl402/String/prototype/localeCompare/default-options-object-prototype.js
new file mode 100644
index 0000000000..dac753245b
--- /dev/null
+++ b/js/src/tests/test262/intl402/String/prototype/localeCompare/default-options-object-prototype.js
@@ -0,0 +1,21 @@
+// Copyright (C) 2017 Daniel Ehrenberg. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-initializecollator
+description: >
+ Monkey-patching Object.prototype does not change the default
+ options for Collator as a null prototype is used.
+info: |
+ InitializeCollator ( collator, locales, options )
+
+ 1. If _options_ is *undefined*, then
+ 1. Let _options_ be ObjectCreate(*null*).
+---*/
+
+if (new Intl.Collator("en").resolvedOptions().locale === "en") {
+ Object.prototype.sensitivity = "base";
+ assert.sameValue("a".localeCompare("A"), -1);
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/String/prototype/localeCompare/length.js b/js/src/tests/test262/intl402/String/prototype/localeCompare/length.js
new file mode 100644
index 0000000000..8fb28c2328
--- /dev/null
+++ b/js/src/tests/test262/intl402/String/prototype/localeCompare/length.js
@@ -0,0 +1,34 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sup-String.prototype.localeCompare
+description: >
+ String.prototype.localeCompare.length is 1.
+info: |
+ String.prototype.localeCompare ( that [ , locales [ , options ] ] )
+
+ 17 ECMAScript Standard Built-in Objects:
+
+ Every built-in function object, including constructors, has a length
+ property whose value is an integer. Unless otherwise specified, this
+ value is equal to the largest number of named arguments shown in the
+ subclause headings for the function description. Optional parameters
+ (which are indicated with brackets: [ ]) or rest parameters (which
+ are shown using the form «...name») are not included in the default
+ argument count.
+ Unless otherwise specified, the length property of a built-in function
+ object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
+ [[Configurable]]: true }.
+
+includes: [propertyHelper.js]
+---*/
+
+verifyProperty(String.prototype.localeCompare, "length", {
+ value: 1,
+ writable: false,
+ enumerable: false,
+ configurable: true,
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/String/prototype/localeCompare/missing-arguments-coerced-to-undefined.js b/js/src/tests/test262/intl402/String/prototype/localeCompare/missing-arguments-coerced-to-undefined.js
new file mode 100644
index 0000000000..2b80e84a89
--- /dev/null
+++ b/js/src/tests/test262/intl402/String/prototype/localeCompare/missing-arguments-coerced-to-undefined.js
@@ -0,0 +1,21 @@
+// Copyright 2013 Mozilla Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/*---
+es5id: 13.1.1_3_2
+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];
+ assert.sameValue(thisValue.localeCompare(), thisValue.localeCompare(undefined), "String.prototype.localeCompare does not treat missing 'that' argument as undefined.");
+ assert.sameValue(thisValue.localeCompare(undefined), thisValue.localeCompare("undefined"), "String.prototype.localeCompare does not treat undefined 'that' argument as \"undefined\".");
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/String/prototype/localeCompare/return-abrupt-this-value.js b/js/src/tests/test262/intl402/String/prototype/localeCompare/return-abrupt-this-value.js
new file mode 100644
index 0000000000..21de34a98d
--- /dev/null
+++ b/js/src/tests/test262/intl402/String/prototype/localeCompare/return-abrupt-this-value.js
@@ -0,0 +1,20 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es5id: 13.1.1_1
+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) {
+ assert.throws(TypeError, function() {
+ var result = String.prototype.localeCompare.call(value, "");
+ }, "String.prototype.localeCompare did not reject this = " + value + ".");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/String/prototype/localeCompare/returns-same-results-as-Collator.js b/js/src/tests/test262/intl402/String/prototype/localeCompare/returns-same-results-as-Collator.js
new file mode 100644
index 0000000000..c93530777d
--- /dev/null
+++ b/js/src/tests/test262/intl402/String/prototype/localeCompare/returns-same-results-as-Collator.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.
+
+/*---
+es5id: 13.1.1_7
+description: >
+ Tests that localeCompare produces the same results as
+ Intl.Collator.
+author: Norbert Lindenberg
+includes: [compareArray.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); });
+ assert.compareArray(strings, referenceSorted,
+ "(Testing with locales " + locales + "; options " + JSON.stringify(options) + ".)");
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/String/prototype/localeCompare/shell.js b/js/src/tests/test262/intl402/String/prototype/localeCompare/shell.js
new file mode 100644
index 0000000000..eda1477282
--- /dev/null
+++ b/js/src/tests/test262/intl402/String/prototype/localeCompare/shell.js
@@ -0,0 +1,24 @@
+// GENERATED, DO NOT EDIT
+// file: isConstructor.js
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: |
+ Test if a given function is a constructor function.
+defines: [isConstructor]
+features: [Reflect.construct]
+---*/
+
+function isConstructor(f) {
+ if (typeof f !== "function") {
+ throw new Test262Error("isConstructor invoked with a non-function value");
+ }
+
+ try {
+ Reflect.construct(function(){}, [], f);
+ } catch (e) {
+ return false;
+ }
+ return true;
+}
diff --git a/js/src/tests/test262/intl402/String/prototype/localeCompare/taint-Intl-Collator.js b/js/src/tests/test262/intl402/String/prototype/localeCompare/taint-Intl-Collator.js
new file mode 100644
index 0000000000..2955b6a8f0
--- /dev/null
+++ b/js/src/tests/test262/intl402/String/prototype/localeCompare/taint-Intl-Collator.js
@@ -0,0 +1,16 @@
+// Copyright 2013 Mozilla Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/*---
+es5id: 13.1.1_6_2
+description: >
+ Tests that String.prototype.localeCompare uses the standard
+ built-in Intl.Collator constructor.
+author: Norbert Lindenberg
+includes: [testIntl.js]
+---*/
+
+taintDataProperty(Intl, "Collator");
+"a".localeCompare("b");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/String/prototype/localeCompare/that-arg-coerced-to-string.js b/js/src/tests/test262/intl402/String/prototype/localeCompare/that-arg-coerced-to-string.js
new file mode 100644
index 0000000000..8de5a8129c
--- /dev/null
+++ b/js/src/tests/test262/intl402/String/prototype/localeCompare/that-arg-coerced-to-string.js
@@ -0,0 +1,22 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es5id: 13.1.1_3_1
+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]);
+ assert.sameValue((result === 0), (i === j), "localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as " + (result === 0 ? "equal" : "different") + ".");
+ }
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/String/prototype/localeCompare/this-value-coerced-to-string.js b/js/src/tests/test262/intl402/String/prototype/localeCompare/this-value-coerced-to-string.js
new file mode 100644
index 0000000000..b8c999059e
--- /dev/null
+++ b/js/src/tests/test262/intl402/String/prototype/localeCompare/this-value-coerced-to-string.js
@@ -0,0 +1,22 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es5id: 13.1.1_2
+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]);
+ assert.sameValue((result === 0), (i === j), "localeCompare treats " + thisValues[i] + " and " + thatValues[j] + " as " + (result === 0 ? "equal" : "different") + ".");
+ }
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/String/prototype/localeCompare/throws-same-exceptions-as-Collator.js b/js/src/tests/test262/intl402/String/prototype/localeCompare/throws-same-exceptions-as-Collator.js
new file mode 100644
index 0000000000..3910154616
--- /dev/null
+++ b/js/src/tests/test262/intl402/String/prototype/localeCompare/throws-same-exceptions-as-Collator.js
@@ -0,0 +1,47 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es5id: 13.1.1_6_1
+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;
+ }
+ assert.notSameValue(referenceError, undefined, "Internal error: Expected exception was not thrown by Intl.Collator for locales " + locales + ".");
+
+ assert.throws(referenceError.constructor, function() {
+ var result = "".localeCompare("", locales);
+ }, "String.prototype.localeCompare didn't throw exception for locales " + locales + ".");
+});
+
+options.forEach(function (options) {
+ var referenceError, error;
+ try {
+ var collator = new Intl.Collator([], options);
+ } catch (e) {
+ referenceError = e;
+ }
+ assert.notSameValue(referenceError, undefined, "Internal error: Expected exception was not thrown by Intl.Collator for options " + JSON.stringify(options) + ".");
+
+ assert.throws(referenceError.constructor, function() {
+ var result = "".localeCompare("", [], options);
+ }, "String.prototype.localeCompare didn't throw exception for options " + JSON.stringify(options) + ".");
+});
+
+reportCompare(0, 0);