diff options
Diffstat (limited to '')
15 files changed, 421 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/localeCompare/15.5.4.9_3.js b/js/src/tests/test262/built-ins/String/prototype/localeCompare/15.5.4.9_3.js new file mode 100644 index 0000000000..35f29b09bf --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/localeCompare/15.5.4.9_3.js @@ -0,0 +1,25 @@ +// Copyright 2013 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +es5id: 15.5.4.9_3 +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)) { + throw new Test262Error("String.prototype.localeCompare does not treat missing 'that' argument as undefined."); + } + if (thisValue.localeCompare(undefined) !== thisValue.localeCompare("undefined")) { + throw new Test262Error("String.prototype.localeCompare does not treat undefined 'that' argument as \"undefined\"."); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/localeCompare/15.5.4.9_CE.js b/js/src/tests/test262/built-ins/String/prototype/localeCompare/15.5.4.9_CE.js new file mode 100644 index 0000000000..65f9289ccb --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/localeCompare/15.5.4.9_CE.js @@ -0,0 +1,78 @@ +// Copyright 2012 Norbert Lindenberg. All rights reserved. +// Copyright 2012 Mozilla Corporation. All rights reserved. +// Copyright 2013 Microsoft Corporation. All rights reserved. +// Copyright (C) 2022 Richard Gibson. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + String.prototype.localeCompare must return 0 when + comparing Strings that are considered canonically equivalent by + the Unicode Standard. +esid: sec-string.prototype.localecompare +info: | + String.prototype.localeCompare ( _that_ [ , _reserved1_ [ , _reserved2_ ] ] ) + + This function must treat Strings that are canonically equivalent + according to the Unicode standard as identical and must return `0` + when comparing Strings that are considered canonically equivalent. +---*/ + +// pairs with characters not in Unicode 3.0 are commented out +var pairs = [ + // example from Unicode 5.0, section 3.7, definition D70 + ["o\u0308", "ö"], + // examples from Unicode 5.0, chapter 3.11 + ["ä\u0323", "a\u0323\u0308"], + ["a\u0308\u0323", "a\u0323\u0308"], + ["ạ\u0308", "a\u0323\u0308"], + ["ä\u0306", "a\u0308\u0306"], + ["ă\u0308", "a\u0306\u0308"], + // example from Unicode 5.0, chapter 3.12 + ["\u1111\u1171\u11B6", "퓛"], + // examples from UTS 10, Unicode Collation Algorithm + ["Å", "Å"], + ["Å", "A\u030A"], + ["x\u031B\u0323", "x\u0323\u031B"], + ["ự", "ụ\u031B"], + ["ự", "u\u031B\u0323"], + ["ự", "ư\u0323"], + ["ự", "u\u0323\u031B"], + // examples from UAX 15, Unicode Normalization Forms + ["Ç", "C\u0327"], + ["q\u0307\u0323", "q\u0323\u0307"], + ["가", "\u1100\u1161"], + ["Å", "A\u030A"], + ["Ω", "Ω"], + ["Å", "A\u030A"], + ["ô", "o\u0302"], + ["ṩ", "s\u0323\u0307"], + ["ḋ\u0323", "d\u0323\u0307"], + ["ḋ\u0323", "ḍ\u0307"], + ["q\u0307\u0323", "q\u0323\u0307"], + // examples involving supplementary characters from UCD NormalizationTest.txt + // ["\uD834\uDD5E", "\uD834\uDD57\uD834\uDD65"], + // ["\uD87E\uDC2B", "北"] +]; + +var i; +for (i = 0; i < pairs.length; i++) { + var pair = pairs[i]; + if (pair[0].localeCompare(pair[1]) !== 0) { + throw new Test262Error("String.prototype.localeCompare considers " + pair[0] + " (" + toU(pair[0]) + + ") ≠ " + pair[1] + " (" + toU(pair[1]) + ")."); + } +} + +function toU(s) { + var result = ""; + var escape = "\\u0000"; + var i; + for (i = 0; i < s.length; i++) { + var hex = s.charCodeAt(i).toString(16); + result += escape.substring(0, escape.length - hex.length) + hex; + } + return result; +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A10.js b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A10.js new file mode 100644 index 0000000000..54f9d6a752 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A10.js @@ -0,0 +1,37 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The String.prototype.localeCompare.length property has the attribute + ReadOnly +es5id: 15.5.4.9_A10 +description: > + Checking if varying the String.prototype.localeCompare.length + property fails +includes: [propertyHelper.js] +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (!(String.prototype.localeCompare.hasOwnProperty('length'))) { + throw new Test262Error('#1: String.prototype.localeCompare.hasOwnProperty(\'length\') return true. Actual: ' + String.prototype.localeCompare.hasOwnProperty('length')); +} +// +////////////////////////////////////////////////////////////////////////////// + +var __obj = String.prototype.localeCompare.length; + +verifyNotWritable(String.prototype.localeCompare, "length", null, function() { + return "shifted"; +}); + +////////////////////////////////////////////////////////////////////////////// +//CHECK#2 +if (String.prototype.localeCompare.length !== __obj) { + throw new Test262Error('#2: __obj = String.prototype.localeCompare.length; String.prototype.localeCompare.length = function(){return "shifted";}; String.prototype.localeCompare.length === __obj. Actual: ' + String.prototype.localeCompare.length); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A11.js b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A11.js new file mode 100644 index 0000000000..c918779e18 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A11.js @@ -0,0 +1,26 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The length property of the localeCompare method is 1 +es5id: 15.5.4.9_A11 +description: Checking String.prototype.localeCompare.length +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (!(String.prototype.localeCompare.hasOwnProperty("length"))) { + throw new Test262Error('#1: String.prototype.localeCompare.hasOwnProperty("length") return true. Actual: ' + String.prototype.localeCompare.hasOwnProperty("length")); +} +// +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +//CHECK#2 +if (String.prototype.localeCompare.length !== 1) { + throw new Test262Error('#2: String.prototype.localeCompare.length === 1. Actual: ' + String.prototype.localeCompare.length); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A1_T1.js b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A1_T1.js new file mode 100644 index 0000000000..1ee5c6feed --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A1_T1.js @@ -0,0 +1,29 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.localeCompare(that) +es5id: 15.5.4.9_A1_T1 +description: This string is symbol and arguments are symbols +---*/ + +var str1 = new String("h"); +//CHECK#1 +var str2 = new String("\x68"); +if (str1.localeCompare(str2) !== 0) { + throw new Test262Error('#1: var str1 = new String("h"); var str2 = new String ("\\x68"); str1.localeCompare(str2)===0. Actual: ' + str1.localeCompare(str2)); +} + +//CHECK#2 +var str2 = new String("\u0068"); +if (str1.localeCompare(str2) !== 0) { + throw new Test262Error('#2: var str1 = new String("h"); var str2 = new String ("\\u0068"); str1.localeCompare(str2)===0. Actual: ' + str1.localeCompare(str2)); +} + +//CHECK#3 +var str2 = new String("h"); +if (str1.localeCompare(str2) !== 0) { + throw new Test262Error('#3: var str1 = new String("h"); var str2 = new String ("h"); str1.localeCompare(str2)===0. Actual: ' + str1.localeCompare(str2)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A1_T2.js b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A1_T2.js new file mode 100644 index 0000000000..c1e239905a --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A1_T2.js @@ -0,0 +1,19 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.localeCompare(that) +es5id: 15.5.4.9_A1_T2 +description: > + Call string_1.localeCompare(string_2) is equal + -string_2.localeCompare(string_1) +---*/ + +//CHECK#1 +var str1 = "h"; +var str2 = "H"; +if (str1.localeCompare(str2) !== -str2.localeCompare(str1)) { + throw new Test262Error('#1.1: var str1 = "h"; var str2 = "H"; str1.localeCompare(str2)===-str2.localeCompare(str1). Actual: ' + str1.localeCompare(str2)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A6.js b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A6.js new file mode 100644 index 0000000000..0123826201 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A6.js @@ -0,0 +1,18 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.localeCompare has not prototype property +es5id: 15.5.4.9_A6 +description: Checking String.prototype.localeCompare.prototype +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (String.prototype.localeCompare.prototype !== undefined) { + throw new Test262Error('#1: String.prototype.localeCompare.prototype === undefined. Actual: ' + String.prototype.localeCompare.prototype); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A7.js b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A7.js new file mode 100644 index 0000000000..70b08ba27f --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A7.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: String.prototype.localeCompare can't be used as constructor +es5id: 15.5.4.9_A7 +description: > + Checking if creating the String.prototype.localeCompare object + fails +---*/ + +var __FACTORY = String.prototype.localeCompare; + +try { + var __instance = new __FACTORY; + throw new Test262Error('#1: __FACTORY = String.prototype.localeCompare; __instance = new __FACTORY lead to throwing exception'); +} catch (e) { + if (e instanceof Test262Error) throw e; +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A8.js b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A8.js new file mode 100644 index 0000000000..09b84b3a31 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A8.js @@ -0,0 +1,45 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The String.prototype.localeCompare.length property has the attribute + DontEnum +es5id: 15.5.4.9_A8 +description: > + Checking if enumerating the String.prototype.localeCompare.length + property fails +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#0 +if (!(String.prototype.localeCompare.hasOwnProperty('length'))) { + throw new Test262Error('#0: String.prototype.localeCompare.hasOwnProperty(\'length\') return true. Actual: ' + String.prototype.localeCompare.hasOwnProperty('length')); +} +// +////////////////////////////////////////////////////////////////////////////// + + +////////////////////////////////////////////////////////////////////////////// +// CHECK#1 +if (String.prototype.localeCompare.propertyIsEnumerable('length')) { + throw new Test262Error('#1: String.prototype.localeCompare.propertyIsEnumerable(\'length\') return false'); +} +// +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +// CHECK#2 +var count = 0; + +for (var p in String.prototype.localeCompare) { + if (p === "length") count++; +} + +if (count !== 0) { + throw new Test262Error('#2: count=0; for (p in String.prototype.localeCompare){if (p==="length") count++;}; count === 0. Actual: ' + count); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A9.js b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A9.js new file mode 100644 index 0000000000..fe5f58266e --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/localeCompare/S15.5.4.9_A9.js @@ -0,0 +1,38 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The String.prototype.localeCompare.length property does not have the + attribute DontDelete +es5id: 15.5.4.9_A9 +description: > + Checking if deleting the String.prototype.localeCompare.length + property fails +---*/ + +////////////////////////////////////////////////////////////////////////////// +//CHECK#0 +if (!(String.prototype.localeCompare.hasOwnProperty('length'))) { + throw new Test262Error('#0: String.prototype.localeCompare.hasOwnProperty(\'length\') return true. Actual: ' + String.prototype.localeCompare.hasOwnProperty('length')); +} +// +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +//CHECK#1 +if (!delete String.prototype.localeCompare.length) { + throw new Test262Error('#1: delete String.prototype.localeCompare.length return true'); +} +// +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +//CHECK#2 +if (String.prototype.localeCompare.hasOwnProperty('length')) { + throw new Test262Error('#2: delete String.prototype.localeCompare.length; String.prototype.localeCompare.hasOwnProperty(\'length\') return false. Actual: ' + String.prototype.localeCompare.hasOwnProperty('length')); +} +// +////////////////////////////////////////////////////////////////////////////// + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/localeCompare/browser.js b/js/src/tests/test262/built-ins/String/prototype/localeCompare/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/localeCompare/browser.js diff --git a/js/src/tests/test262/built-ins/String/prototype/localeCompare/name.js b/js/src/tests/test262/built-ins/String/prototype/localeCompare/name.js new file mode 100644 index 0000000000..81a2062386 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/localeCompare/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.1.3.10 +description: > + String.prototype.localeCompare.name is "localeCompare". +info: | + String.prototype.localeCompare ( that [, reserved1 [ , reserved2 ] ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(String.prototype.localeCompare.name, "localeCompare"); + +verifyNotEnumerable(String.prototype.localeCompare, "name"); +verifyNotWritable(String.prototype.localeCompare, "name"); +verifyConfigurable(String.prototype.localeCompare, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/localeCompare/not-a-constructor.js b/js/src/tests/test262/built-ins/String/prototype/localeCompare/not-a-constructor.js new file mode 100644 index 0000000000..c335172ddc --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/localeCompare/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.localeCompare does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.localeCompare), + false, + 'isConstructor(String.prototype.localeCompare) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.localeCompare(); +}, '`new String.prototype.localeCompare()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/localeCompare/shell.js b/js/src/tests/test262/built-ins/String/prototype/localeCompare/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/localeCompare/shell.js diff --git a/js/src/tests/test262/built-ins/String/prototype/localeCompare/this-value-not-obj-coercible.js b/js/src/tests/test262/built-ins/String/prototype/localeCompare/this-value-not-obj-coercible.js new file mode 100644 index 0000000000..c76b2750f4 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/localeCompare/this-value-not-obj-coercible.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.localecompare +description: The "this" value must be object-coercible +info: | + 1. Let O be ? RequireObjectCoercible(this value). +---*/ + +var localeCompare = String.prototype.localeCompare; + +assert.sameValue(typeof localeCompare, 'function'); + +assert.throws(TypeError, function() { + localeCompare.call(undefined, ''); +}, 'undefined'); + +assert.throws(TypeError, function() { + localeCompare.call(null, ''); +}, 'null'); + +reportCompare(0, 0); |