diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/test262/intl402/Collator | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/intl402/Collator')
72 files changed, 1748 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/Collator/browser.js b/js/src/tests/test262/intl402/Collator/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/browser.js diff --git a/js/src/tests/test262/intl402/Collator/builtin.js b/js/src/tests/test262/intl402/Collator/builtin.js new file mode 100644 index 0000000000..ea9bf9465f --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/builtin.js @@ -0,0 +1,21 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +es5id: 10.1_L15 +description: > + Tests that Intl.Collator meets the requirements for built-in + objects defined by the introduction of chapter 17 of the + ECMAScript Language Specification. +author: Norbert Lindenberg +---*/ + +assert.sameValue(Object.prototype.toString.call(Intl.Collator), "[object Function]", + "The [[Class]] internal property of a built-in function must be " + + "\"Function\"."); + +assert(Object.isExtensible(Intl.Collator), "Built-in objects must be extensible."); + +assert.sameValue(Object.getPrototypeOf(Intl.Collator), Function.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/constructor-options-throwing-getters.js b/js/src/tests/test262/intl402/Collator/constructor-options-throwing-getters.js new file mode 100644 index 0000000000..ed2993524c --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/constructor-options-throwing-getters.js @@ -0,0 +1,31 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-initializecollator +description: Checks the propagation of exceptions from the options for the Collator constructor. +---*/ + +function CustomError() {} + +const options = [ + "usage", + "localeMatcher", + "collation", + "numeric", + "caseFirst", + "sensitivity", + "ignorePunctuation", +]; + +for (const option of options) { + assert.throws(CustomError, () => { + new Intl.Collator("en", { + get [option]() { + throw new CustomError(); + } + }); + }, `Exception from ${option} getter should be propagated`); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/default-options-object-prototype.js b/js/src/tests/test262/intl402/Collator/default-options-object-prototype.js new file mode 100644 index 0000000000..7b699fe36a --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/default-options-object-prototype.js @@ -0,0 +1,22 @@ +// 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*). +---*/ + +let defaultSensitivity = new Intl.Collator("en").resolvedOptions().sensitivity; + +Object.prototype.sensitivity = "base"; +let collator = new Intl.Collator("en"); +assert.sameValue(collator.resolvedOptions().sensitivity, defaultSensitivity); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/ignore-invalid-unicode-ext-values.js b/js/src/tests/test262/intl402/Collator/ignore-invalid-unicode-ext-values.js new file mode 100644 index 0000000000..0e36be1160 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/ignore-invalid-unicode-ext-values.js @@ -0,0 +1,48 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +es5id: 10.2.3_b +description: > + Tests that Intl.Collator does not accept Unicode locale extension + keys and values that are not allowed. +author: Norbert Lindenberg +includes: [compareArray.js] +---*/ + +var testArray = [ + "hello", "你好", "こんにちは", + "pêche", "peché", "1", "9", "10", + "ụ\u031B", "u\u031B\u0323", "ư\u0323", "u\u0323\u031B", + "Å", "Å", "A\u030A" +]; + +var defaultCollator = new Intl.Collator(); +var defaultOptions = defaultCollator.resolvedOptions(); +var defaultOptionsJSON = JSON.stringify(defaultOptions); +var defaultLocale = defaultOptions.locale; +var defaultSortedArray = testArray.slice(0).sort(defaultCollator.compare); + +var keyValues = { + "co": ["standard", "search", "invalid"], + "ka": ["noignore", "shifted", "invalid"], + "kb": ["true", "false", "invalid"], + "kc": ["true", "false", "invalid"], + "kh": ["true", "false", "invalid"], + "kk": ["true", "false", "invalid"], + "kr": ["latn-hira-hani", "hani-hira-latn", "invalid"], + "ks": ["level1", "level2", "level3", "level4", "identic", "invalid"], + "vt": ["1234-5678-9abc-edf0", "invalid"] +}; + +Object.getOwnPropertyNames(keyValues).forEach(function (key) { + keyValues[key].forEach(function (value) { + var collator = new Intl.Collator([defaultLocale + "-u-" + key + "-" + value]); + var options = collator.resolvedOptions(); + assert.sameValue(options.locale, defaultLocale, "Locale " + options.locale + " is affected by key " + key + "; value " + value + "."); + assert.sameValue(JSON.stringify(options), defaultOptionsJSON, "Resolved options " + JSON.stringify(options) + " are affected by key " + key + "; value " + value + "."); + assert.compareArray(testArray.sort(collator.compare), defaultSortedArray); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/instance-proto-and-extensible.js b/js/src/tests/test262/intl402/Collator/instance-proto-and-extensible.js new file mode 100644 index 0000000000..ba37de24f4 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/instance-proto-and-extensible.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. + +/*--- +es5id: 10.1.3 +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); +assert.sameValue(actualPrototype, Intl.Collator.prototype, "Prototype of object constructed by Intl.Collator isn't Intl.Collator.prototype."); + +assert(Object.isExtensible(obj), "Object constructed by Intl.Collator must be extensible."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/legacy-regexp-statics-not-modified.js b/js/src/tests/test262/intl402/Collator/legacy-regexp-statics-not-modified.js new file mode 100644 index 0000000000..9d1b16d6e5 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/legacy-regexp-statics-not-modified.js @@ -0,0 +1,17 @@ +// Copyright 2013 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 10.1.1_a +description: > + Tests that constructing a Collator doesn't create or modify + unwanted properties on the RegExp constructor. +author: Norbert Lindenberg +includes: [testIntl.js] +---*/ + +testForUnwantedRegExpChanges(function () { + new Intl.Collator("de-DE-u-co-phonebk"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/length.js b/js/src/tests/test262/intl402/Collator/length.js new file mode 100644 index 0000000000..335bcb2b96 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator +description: > + Intl.Collator.length is 0. +info: | + Intl.Collator ( [ 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] +---*/ + +assert.sameValue(Intl.Collator.length, 0); + +verifyNotEnumerable(Intl.Collator, "length"); +verifyNotWritable(Intl.Collator, "length"); +verifyConfigurable(Intl.Collator, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/missing-unicode-ext-value-defaults-to-true.js b/js/src/tests/test262/intl402/Collator/missing-unicode-ext-value-defaults-to-true.js new file mode 100644 index 0000000000..29be350876 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/missing-unicode-ext-value-defaults-to-true.js @@ -0,0 +1,27 @@ +// 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. + +/*--- +es5id: 9.2.5_11_g_ii_2 +description: > + Tests that missing Unicode extension values default to true for + boolean keys. +author: Norbert Lindenberg +---*/ + +var extensions = ["-u-co-phonebk-kn", "-u-kn-co-phonebk", "-u-co-phonebk-kn-true", "-u-kn-true-co-phonebk"]; +extensions.forEach(function (extension) { + var defaultLocale = new Intl.Collator().resolvedOptions().locale; + var collator = new Intl.Collator([defaultLocale + extension], {usage: "sort"}); + var locale = collator.resolvedOptions().locale; + var numeric = collator.resolvedOptions().numeric; + if (numeric !== undefined) { + assert.sameValue(numeric, true, "Default value for \"kn\" should be true, but is " + numeric + "."); + assert.sameValue(locale.indexOf("-kn-false"), -1, "\"kn-false\" is returned in locale, but shouldn't be."); + assert.sameValue(locale.indexOf("-kn-true"), -1, "\"kn-true\" is returned in locale, but shouldn't be."); + assert.sameValue(locale.indexOf("-kn") >= 0, true, "\"kn\" should be returned in locale."); + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/name.js b/js/src/tests/test262/intl402/Collator/name.js new file mode 100644 index 0000000000..36dd6f5885 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Collator +description: > + Intl.Collator.name is "Collator". +info: | + 10.1.2 Intl.Collator ([ locales [ , options ]]) + + 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(Intl.Collator.name, "Collator"); + +verifyNotEnumerable(Intl.Collator, "name"); +verifyNotWritable(Intl.Collator, "name"); +verifyConfigurable(Intl.Collator, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/numeric-and-caseFirst.js b/js/src/tests/test262/intl402/Collator/numeric-and-caseFirst.js new file mode 100644 index 0000000000..6953fe1b08 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/numeric-and-caseFirst.js @@ -0,0 +1,58 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 10.1.1_19_c +description: > + Tests that the options numeric and caseFirst can be set through + either the locale or the options. +author: Norbert Lindenberg +---*/ + +var options = [ + {key: "kn", property: "numeric", 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]; + assert.sameValue(result, value, "Property " + option.property + " couldn't be set through locale extension key " + option.key + "."); + }); + + // 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]; + assert.sameValue(result, value, "Options value for property " + option.property + " doesn't override locale extension key " + option.key + "."); + } + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prop-desc.js b/js/src/tests/test262/intl402/Collator/prop-desc.js new file mode 100644 index 0000000000..a7240fbdd1 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prop-desc.js @@ -0,0 +1,31 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator-intro +description: > + "Collator" property of Intl. +info: | + Intl.Collator (...) + + 7 Requirements for Standard Built-in ECMAScript Objects + + Unless specified otherwise in this document, the objects, functions, and constructors + described in this standard are subject to the generic requirements and restrictions + specified for standard built-in ECMAScript objects in the ECMAScript 2018 Language + Specification, 9th edition, clause 17, or successor. + + 17 ECMAScript Standard Built-in Objects: + + Every other data property described in clauses 18 through 26 and in Annex B.2 has the + attributes { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true } + unless otherwise specified. + +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(Intl, "Collator"); +verifyWritable(Intl, "Collator"); +verifyConfigurable(Intl, "Collator"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/proto-from-ctor-realm.js b/js/src/tests/test262/intl402/Collator/proto-from-ctor-realm.js new file mode 100644 index 0000000000..473b816dad --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/proto-from-ctor-realm.js @@ -0,0 +1,60 @@ +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator +description: Default [[Prototype]] value derived from realm of the NewTarget. +info: | + Intl.Collator ( [ locales [ , options ] ] ) + + 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget. + ... + 5. Let collator be ? OrdinaryCreateFromConstructor(newTarget, "%CollatorPrototype%", internalSlotsList). + 6. Return ? InitializeCollator(collator, locales, options). + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, 'prototype'). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +features: [cross-realm, Reflect, Symbol] +---*/ + +var other = $262.createRealm().global; +var newTarget = new other.Function(); +var col; + +newTarget.prototype = undefined; +col = Reflect.construct(Intl.Collator, [], newTarget); +assert.sameValue(Object.getPrototypeOf(col), other.Intl.Collator.prototype, 'newTarget.prototype is undefined'); + +newTarget.prototype = null; +col = Reflect.construct(Intl.Collator, [], newTarget); +assert.sameValue(Object.getPrototypeOf(col), other.Intl.Collator.prototype, 'newTarget.prototype is null'); + +newTarget.prototype = true; +col = Reflect.construct(Intl.Collator, [], newTarget); +assert.sameValue(Object.getPrototypeOf(col), other.Intl.Collator.prototype, 'newTarget.prototype is a Boolean'); + +newTarget.prototype = ''; +col = Reflect.construct(Intl.Collator, [], newTarget); +assert.sameValue(Object.getPrototypeOf(col), other.Intl.Collator.prototype, 'newTarget.prototype is a String'); + +newTarget.prototype = Symbol(); +col = Reflect.construct(Intl.Collator, [], newTarget); +assert.sameValue(Object.getPrototypeOf(col), other.Intl.Collator.prototype, 'newTarget.prototype is a Symbol'); + +newTarget.prototype = 1; +col = Reflect.construct(Intl.Collator, [], newTarget); +assert.sameValue(Object.getPrototypeOf(col), other.Intl.Collator.prototype, 'newTarget.prototype is a Number'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/browser.js b/js/src/tests/test262/intl402/Collator/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/browser.js diff --git a/js/src/tests/test262/intl402/Collator/prototype/builtin.js b/js/src/tests/test262/intl402/Collator/prototype/builtin.js new file mode 100644 index 0000000000..d43c58095d --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/builtin.js @@ -0,0 +1,18 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +es5id: 10.3_L15 +description: > + Tests that Intl.Collator.prototype meets the requirements for + built-in objects defined by the introduction of chapter 17 of the + ECMAScript Language Specification. +author: Norbert Lindenberg +---*/ + +assert(Object.isExtensible(Intl.Collator.prototype), "Built-in objects must be extensible."); + +assert.sameValue(Object.getPrototypeOf(Intl.Collator.prototype), Object.prototype, + "Built-in prototype objects must have Object.prototype as their prototype."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/compare/bound-to-collator-instance.js b/js/src/tests/test262/intl402/Collator/prototype/compare/bound-to-collator-instance.js new file mode 100644 index 0000000000..a5d3716700 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/compare/bound-to-collator-instance.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. + +/*--- +es5id: 10.3.2_1_c +description: Tests that compare function is bound to its 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 collatorObj = new Intl.Collator(locales, options); + var compareFunc = collatorObj.compare; + var referenceSorted = strings.slice(); + referenceSorted.sort(function (a, b) { return collatorObj.compare(a, b); }); + var sorted = strings; + sorted.sort(compareFunc); + assert.compareArray(sorted, referenceSorted, + "(Testing with locales " + locales + "; options " + + (options ? JSON.stringify(options) : options) + ".)"); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/compare/browser.js b/js/src/tests/test262/intl402/Collator/prototype/compare/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/compare/browser.js diff --git a/js/src/tests/test262/intl402/Collator/prototype/compare/builtin.js b/js/src/tests/test262/intl402/Collator/prototype/compare/builtin.js new file mode 100644 index 0000000000..11ccc40a7b --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/compare/builtin.js @@ -0,0 +1,32 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +es5id: 10.3.2_L15 +description: > + Tests that the getter for Intl.Collator.prototype.compare 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] +---*/ + +var compareFn = Object.getOwnPropertyDescriptor(Intl.Collator.prototype, "compare").get; + +assert.sameValue(Object.prototype.toString.call(compareFn), "[object Function]", + "The [[Class]] internal property of a built-in function must be " + + "\"Function\"."); + +assert(Object.isExtensible(compareFn), + "Built-in objects must be extensible."); + +assert.sameValue(Object.getPrototypeOf(compareFn), Function.prototype); + +assert.sameValue(compareFn.hasOwnProperty("prototype"), false, + "Built-in functions that aren't constructors must not have a prototype property."); + +assert.sameValue(isConstructor(compareFn), false, + "Built-in functions don't implement [[Construct]] unless explicitly specified."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/compare/canonically-equivalent-strings.js b/js/src/tests/test262/intl402/Collator/prototype/compare/canonically-equivalent-strings.js new file mode 100644 index 0000000000..a0994462b7 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/compare/canonically-equivalent-strings.js @@ -0,0 +1,69 @@ +// Copyright 2012 Norbert Lindenberg. All rights reserved. +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +es5id: 10.3.2_CS_a +description: > + Tests that the function returned by + Intl.Collator.prototype.compare returns 0 when comparing Strings + that are considered canonically equivalent by the Unicode + standard. +author: Norbert Lindenberg +---*/ + +var collator = new Intl.Collator(); +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]; + assert.sameValue(collator.compare(pair[0], pair[1]), 0, "Collator.compare 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/intl402/Collator/prototype/compare/compare-function-builtin.js b/js/src/tests/test262/intl402/Collator/prototype/compare/compare-function-builtin.js new file mode 100644 index 0000000000..3b6ec70b35 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/compare/compare-function-builtin.js @@ -0,0 +1,33 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +es5id: 10.3.2_1_a_L15 +description: > + Tests that the function returned by + Intl.Collator.prototype.compare 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] +---*/ + +var compareFn = new Intl.Collator().compare; + +assert.sameValue(Object.prototype.toString.call(compareFn), "[object Function]", + "The [[Class]] internal property of a built-in function must be " + + "\"Function\"."); + +assert(Object.isExtensible(compareFn), + "Built-in objects must be extensible."); + +assert.sameValue(Object.getPrototypeOf(compareFn), Function.prototype); + +assert.sameValue(compareFn.hasOwnProperty("prototype"), false, + "Built-in functions that aren't constructors must not have a prototype property."); + +assert.sameValue(isConstructor(compareFn), false, + "Built-in functions don't implement [[Construct]] unless explicitly specified."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/compare/compare-function-length.js b/js/src/tests/test262/intl402/Collator/prototype/compare/compare-function-length.js new file mode 100644 index 0000000000..ca9764bbb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/compare/compare-function-length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator.prototype.compare +description: > + The length of the bound Collator compare function is 2. +info: | + get Intl.Collator.prototype.compare + + ... + 4. If collator.[[BoundCompare]] is undefined, then + a. Let F be a new built-in function object as defined in 10.3.4. + b. Let bc be BoundFunctionCreate(F, collator, « »). + c. Perform ! DefinePropertyOrThrow(bc, "length", PropertyDescriptor {[[Value]]: 2, + [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true}). + ... + +includes: [propertyHelper.js] +---*/ + +var compareFn = new Intl.Collator().compare; + +assert.sameValue(compareFn.length, 2); + +verifyNotEnumerable(compareFn, "length"); +verifyNotWritable(compareFn, "length"); +verifyConfigurable(compareFn, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/compare/compare-function-name.js b/js/src/tests/test262/intl402/Collator/prototype/compare/compare-function-name.js new file mode 100644 index 0000000000..234ef6ad27 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/compare/compare-function-name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Collator.prototype.compare +description: > + The bound Collator compare function is an anonymous function. +info: | + 10.3.3 get Intl.Collator.prototype.compare + + 17 ECMAScript Standard Built-in Objects: + Every built-in function object, including constructors, has a `name` + property whose value is a String. Functions that are identified as + anonymous functions use the empty string as the value of the `name` + property. + Unless otherwise specified, the `name` property of a built-in function + object has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, + [[Configurable]]: *true* }. +includes: [propertyHelper.js] +---*/ + +var compareFn = new Intl.Collator().compare; + +verifyProperty(compareFn, "name", { + value: "", writable: false, enumerable: false, configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/compare/length.js b/js/src/tests/test262/intl402/Collator/prototype/compare/length.js new file mode 100644 index 0000000000..e4774e2eae --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/compare/length.js @@ -0,0 +1,35 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator.prototype.compare +description: > + get Intl.Collator.prototype.compare.length is 0. +info: | + get Intl.Collator.prototype.compare + + 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] +---*/ + +var desc = Object.getOwnPropertyDescriptor(Intl.Collator.prototype, "compare"); + +assert.sameValue(desc.get.length, 0); + +verifyNotEnumerable(desc.get, "length"); +verifyNotWritable(desc.get, "length"); +verifyConfigurable(desc.get, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/compare/name.js b/js/src/tests/test262/intl402/Collator/prototype/compare/name.js new file mode 100644 index 0000000000..8fe0e1dd84 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/compare/name.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Collator.prototype.compare +description: > + get Intl.Collator.prototype.compare.name is "get compare". +info: | + 10.3.3 get Intl.Collator.prototype.compare + + 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] +---*/ + +var desc = Object.getOwnPropertyDescriptor(Intl.Collator.prototype, "compare"); + +assert.sameValue(desc.get.name, "get compare"); + +verifyNotEnumerable(desc.get, "name"); +verifyNotWritable(desc.get, "name"); +verifyConfigurable(desc.get, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/compare/non-normative-basic.js b/js/src/tests/test262/intl402/Collator/prototype/compare/non-normative-basic.js new file mode 100644 index 0000000000..8243ddfd44 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/compare/non-normative-basic.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. + +/*--- +es5id: 10.3.2_CS_b_NN +description: > + Tests that the compare function isn't entirely unreasonable. This + test is not normative. +author: Norbert Lindenberg +includes: [compareArray.js] +---*/ + +// this test should be valid at least for the following locales +var locales = ["de", "en", "es", "fr", "it"]; +locales = Intl.Collator.supportedLocalesOf(locales, {localeMatcher: "lookup"}); +locales.forEach(function (locale) { + var collator = new Intl.Collator([locale], {sensitivity: "variant", localeMatcher: "lookup"}); + var a = ["L", "X", "C", "k", "Z", "H", "d", "m", "w", "A", "i", "f", "y", "E", "N", "V", "g", "J", "b"]; + a.sort(collator.compare); + var expected = ["A", "b", "C", "d", "E", "f", "g", "H", "i", "J", "k", "L", "m", "N", "V", "w", "X", "y", "Z"]; + assert.compareArray(a, expected); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/compare/non-normative-phonebook.js b/js/src/tests/test262/intl402/Collator/prototype/compare/non-normative-phonebook.js new file mode 100644 index 0000000000..47d330eba2 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/compare/non-normative-phonebook.js @@ -0,0 +1,24 @@ +// 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. + +/*--- +es5id: 10.3.2_CS_c_NN +description: > + Tests that the compare function supports phonebook sorting if it + says it does. This test is not normative. +author: Norbert Lindenberg +includes: [compareArray.js] +---*/ + +// this test should be valid at least for the following locales +var locales = ["de-DE-u-co-phonebk", "de-u-co-phonebk"]; +var collator = new Intl.Collator(locales, {localeMatcher: "lookup"}); +if (locales.indexOf(collator.resolvedOptions().locale) !== -1) { + var a = ["A", "b", "Af", "Ab", "od", "off", "Ä", "ö"]; + a.sort(collator.compare); + var expected = ["A", "Ab", "Ä", "Af", "b", "od", "ö", "off"]; + assert.compareArray(a, expected); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/compare/non-normative-sensitivity.js b/js/src/tests/test262/intl402/Collator/prototype/compare/non-normative-sensitivity.js new file mode 100644 index 0000000000..8c5e70ba87 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/compare/non-normative-sensitivity.js @@ -0,0 +1,36 @@ +// 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. + +/*--- +es5id: 10.3.2_CS_d_NN +description: > + Tests that the compare function supports different sensitivity + settings. This test is not normative. +author: Norbert Lindenberg +includes: [compareArray.js] +---*/ + +// this test should be valid at least for the following locales +var locales = ["de", "en", "es", "it"]; +locales = Intl.Collator.supportedLocalesOf(locales, {localeMatcher: "lookup"}); +locales.forEach(function (locale) { + var target = "Aa"; + var input = ["Aa", "bA", "E", "b", "aA", "fC", "áÁ", "Aã"]; + var expected = { + "base": ["Aa", "aA", "áÁ", "Aã"], + "accent": ["Aa", "aA"], + "case": ["Aa", "Aã"], + "variant": ["Aa"] + }; + Object.getOwnPropertyNames(expected).forEach(function (sensitivity) { + var collator = new Intl.Collator([locale], {usage: "search", + sensitivity: sensitivity, localeMatcher: "lookup"}); + var matches = input.filter(function (v) { + return collator.compare(v, target) === 0; + }); + assert.compareArray(matches, expected[sensitivity]); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/compare/prop-desc.js b/js/src/tests/test262/intl402/Collator/prototype/compare/prop-desc.js new file mode 100644 index 0000000000..7ec97afd4c --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/compare/prop-desc.js @@ -0,0 +1,37 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator.prototype.resolvedoptions +description: > + "compare" property of Intl.Collator.prototype. +info: | + get Intl.Collator.prototype.compare + + 7 Requirements for Standard Built-in ECMAScript Objects + + Unless specified otherwise in this document, the objects, functions, and constructors + described in this standard are subject to the generic requirements and restrictions + specified for standard built-in ECMAScript objects in the ECMAScript 2018 Language + Specification, 9th edition, clause 17, or successor. + + 17 ECMAScript Standard Built-in Objects: + + Every accessor property described in clauses 18 through 26 and in Annex B.2 has the + attributes { [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. + If only a get accessor function is described, the set accessor function is the default + value, undefined. If only a set accessor is described the get accessor is the default + value, undefined. + +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(Intl.Collator.prototype, "compare"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyNotEnumerable(Intl.Collator.prototype, "compare"); +verifyConfigurable(Intl.Collator.prototype, "compare"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/compare/shell.js b/js/src/tests/test262/intl402/Collator/prototype/compare/shell.js new file mode 100644 index 0000000000..54371b7789 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/compare/shell.js @@ -0,0 +1,19 @@ +// 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] +---*/ + +function isConstructor(f) { + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/intl402/Collator/prototype/constructor/browser.js b/js/src/tests/test262/intl402/Collator/prototype/constructor/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/constructor/browser.js diff --git a/js/src/tests/test262/intl402/Collator/prototype/constructor/prop-desc.js b/js/src/tests/test262/intl402/Collator/prototype/constructor/prop-desc.js new file mode 100644 index 0000000000..ee4cee4d9b --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/constructor/prop-desc.js @@ -0,0 +1,31 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator.prototype.constructor +description: > + "constructor" property of Intl.Collator.prototype. +info: | + Intl.Collator.prototype.constructor + + 7 Requirements for Standard Built-in ECMAScript Objects + + Unless specified otherwise in this document, the objects, functions, and constructors + described in this standard are subject to the generic requirements and restrictions + specified for standard built-in ECMAScript objects in the ECMAScript 2018 Language + Specification, 9th edition, clause 17, or successor. + + 17 ECMAScript Standard Built-in Objects: + + Every other data property described in clauses 18 through 26 and in Annex B.2 has the + attributes { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true } + unless otherwise specified. + +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(Intl.Collator.prototype, "constructor"); +verifyWritable(Intl.Collator.prototype, "constructor"); +verifyConfigurable(Intl.Collator.prototype, "constructor"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/constructor/shell.js b/js/src/tests/test262/intl402/Collator/prototype/constructor/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/constructor/shell.js diff --git a/js/src/tests/test262/intl402/Collator/prototype/constructor/value.js b/js/src/tests/test262/intl402/Collator/prototype/constructor/value.js new file mode 100644 index 0000000000..37cb53b0c5 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/constructor/value.js @@ -0,0 +1,13 @@ +// Copyright 2012 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 10.3.1 +description: > + Tests that Intl.Collator.prototype.constructor is the + Intl.Collator. +---*/ + +assert.sameValue(Intl.Collator.prototype.constructor, Intl.Collator, "Intl.Collator.prototype.constructor is not the same as Intl.Collator"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/prop-desc.js b/js/src/tests/test262/intl402/Collator/prototype/prop-desc.js new file mode 100644 index 0000000000..52e6fec6b3 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/prop-desc.js @@ -0,0 +1,17 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +es5id: 10.2.1 +description: Tests that Intl.Collator.prototype has the required attributes. +author: Norbert Lindenberg +includes: [propertyHelper.js] +---*/ + +verifyProperty(Intl.Collator, "prototype", { + writable: false, + enumerable: false, + configurable: false, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/basic.js b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/basic.js new file mode 100644 index 0000000000..7f6f5ba604 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/basic.js @@ -0,0 +1,70 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +es5id: 10.3.3 +description: > + Tests that the object returned by + Intl.Collator.prototype.resolvedOptions has the right properties. +author: Norbert Lindenberg +includes: [testIntl.js, propertyHelper.js] +---*/ + +var actual = new Intl.Collator().resolvedOptions(); + +var actual2 = new Intl.Collator().resolvedOptions(); +assert.notSameValue(actual2, actual, "resolvedOptions returned the same object twice."); + +// source: CLDR file common/bcp47/collation.xml; version CLDR 32. +var collations = [ + "default", // added + "big5han", + "compat", + "dict", + "direct", + "ducet", + "emoji", + "eor", + "gb2312", + "phonebk", + "phonetic", + "pinyin", + "reformed", + // "search", // excluded + "searchjl", + // "standard", // excluded + "stroke", + "trad", + "unihan", + "zhuyin", +]; + +// this assumes the default values where the specification provides them +assert(isCanonicalizedStructurallyValidLanguageTag(actual.locale), + "Invalid locale: " + actual.locale); +assert.sameValue(actual.usage, "sort"); +assert.sameValue(actual.sensitivity, "variant"); +assert.sameValue(actual.ignorePunctuation, false); +assert.notSameValue(collations.indexOf(actual.collation), -1, + "Invalid collation: " + actual.collation); + +var dataPropertyDesc = { writable: true, enumerable: true, configurable: true }; +verifyProperty(actual, "locale", dataPropertyDesc); +verifyProperty(actual, "usage", dataPropertyDesc); +verifyProperty(actual, "sensitivity", dataPropertyDesc); +verifyProperty(actual, "ignorePunctuation", dataPropertyDesc); +verifyProperty(actual, "collation", dataPropertyDesc); + +// "numeric" is an optional property. +if (actual.hasOwnProperty("numeric")) { + assert.notSameValue([true, false].indexOf(actual.numeric), -1); + verifyProperty(actual, "numeric", dataPropertyDesc); +} + +// "caseFirst" is an optional property. +if (actual.hasOwnProperty("caseFirst")) { + assert.notSameValue(["upper", "lower", "false"].indexOf(actual.caseFirst), -1); + verifyProperty(actual, "caseFirst", dataPropertyDesc); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/browser.js b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/browser.js diff --git a/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/builtin.js b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/builtin.js new file mode 100644 index 0000000000..6fef5829f6 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/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: 10.3.3_L15 +description: > + Tests that Intl.Collator.prototype.resolvedOptions 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(Intl.Collator.prototype.resolvedOptions), "[object Function]", + "The [[Class]] internal property of a built-in function must be " + + "\"Function\"."); + +assert(Object.isExtensible(Intl.Collator.prototype.resolvedOptions), + "Built-in objects must be extensible."); + +assert.sameValue(Object.getPrototypeOf(Intl.Collator.prototype.resolvedOptions), Function.prototype); + +assert.sameValue(Intl.Collator.prototype.resolvedOptions.hasOwnProperty("prototype"), false, + "Built-in functions that aren't constructors must not have a prototype property."); + +assert.sameValue(isConstructor(Intl.Collator.prototype.resolvedOptions), false, + "Built-in functions don't implement [[Construct]] unless explicitly specified."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/length.js b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/length.js new file mode 100644 index 0000000000..a0ec05d05e --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator.prototype.resolvedoptions +description: > + Intl.Collator.prototype.resolvedOptions.length is 0. +info: | + Intl.Collator.prototype.resolvedOptions () + + 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] +---*/ + +assert.sameValue(Intl.Collator.prototype.resolvedOptions.length, 0); + +verifyNotEnumerable(Intl.Collator.prototype.resolvedOptions, "length"); +verifyNotWritable(Intl.Collator.prototype.resolvedOptions, "length"); +verifyConfigurable(Intl.Collator.prototype.resolvedOptions, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/name.js b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/name.js new file mode 100644 index 0000000000..46b7fde718 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Collator.prototype.resolvedOptions +description: > + Intl.Collator.prototype.resolvedOptions.name is "resolvedOptions". +info: | + 10.3.5 Intl.Collator.prototype.resolvedOptions () + + 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(Intl.Collator.prototype.resolvedOptions.name, "resolvedOptions"); + +verifyNotEnumerable(Intl.Collator.prototype.resolvedOptions, "name"); +verifyNotWritable(Intl.Collator.prototype.resolvedOptions, "name"); +verifyConfigurable(Intl.Collator.prototype.resolvedOptions, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/order.js b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/order.js new file mode 100644 index 0000000000..7e63a9739d --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/order.js @@ -0,0 +1,33 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator.prototype.resolvedoptions +description: Verifies the property order for the object returned by resolvedOptions(). +includes: [compareArray.js] +---*/ + +const options = new Intl.Collator([], { + "numeric": true, + "caseFirst": "upper", +}).resolvedOptions(); + +const expected = [ + "locale", + "usage", + "sensitivity", + "ignorePunctuation", + "collation", +]; + +if ("numeric" in options) { + expected.push("numeric"); +} + +if ("caseFirst" in options) { + expected.push("caseFirst"); +} + +assert.compareArray(Object.getOwnPropertyNames(options), expected); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/prop-desc.js b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/prop-desc.js new file mode 100644 index 0000000000..418bf6ec88 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/prop-desc.js @@ -0,0 +1,31 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator.prototype.resolvedoptions +description: > + "resolvedOptions" property of Intl.Collator.prototype. +info: | + Intl.Collator.prototype.resolvedOptions () + + 7 Requirements for Standard Built-in ECMAScript Objects + + Unless specified otherwise in this document, the objects, functions, and constructors + described in this standard are subject to the generic requirements and restrictions + specified for standard built-in ECMAScript objects in the ECMAScript 2018 Language + Specification, 9th edition, clause 17, or successor. + + 17 ECMAScript Standard Built-in Objects: + + Every other data property described in clauses 18 through 26 and in Annex B.2 has the + attributes { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true } + unless otherwise specified. + +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(Intl.Collator.prototype, "resolvedOptions"); +verifyWritable(Intl.Collator.prototype, "resolvedOptions"); +verifyConfigurable(Intl.Collator.prototype, "resolvedOptions"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/shell.js b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/shell.js new file mode 100644 index 0000000000..54371b7789 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/resolvedOptions/shell.js @@ -0,0 +1,19 @@ +// 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] +---*/ + +function isConstructor(f) { + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/intl402/Collator/prototype/shell.js b/js/src/tests/test262/intl402/Collator/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/shell.js diff --git a/js/src/tests/test262/intl402/Collator/prototype/this-value-collator-prototype.js b/js/src/tests/test262/intl402/Collator/prototype/this-value-collator-prototype.js new file mode 100644 index 0000000000..0ccb9a5f52 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/this-value-collator-prototype.js @@ -0,0 +1,16 @@ +// Copyright 2012 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-intl-collator-prototype-object +description: > + Tests that Intl.Collator.prototype is not an object that has been + initialized as an Intl.Collator. +---*/ + +// test by calling a function that should fail as "this" is not an object +// initialized as an Intl.Collator +assert.throws(TypeError, () => Intl.Collator.prototype.compare("aаあ아", "aаあ아"), + "Intl.Collator.prototype is not an object that has been initialized as an Intl.Collator."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/this-value-not-collator.js b/js/src/tests/test262/intl402/Collator/prototype/this-value-not-collator.js new file mode 100644 index 0000000000..dd75665f46 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/this-value-not-collator.js @@ -0,0 +1,28 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 10.3_b +description: > + Tests that Intl.Collator.prototype functions throw a TypeError if + called on a non-object value or an object that hasn't been + initialized as a Collator. +author: Norbert Lindenberg +---*/ + +var functions = { + "compare getter": Object.getOwnPropertyDescriptor(Intl.Collator.prototype, "compare").get, + resolvedOptions: Intl.Collator.prototype.resolvedOptions +}; +var invalidTargets = [undefined, null, true, 0, "Collator", [], {}]; + +Object.getOwnPropertyNames(functions).forEach(function (functionName) { + var f = functions[functionName]; + invalidTargets.forEach(function (target) { + assert.throws(TypeError, function() { + f.call(target); + }, "Calling " + functionName + " on " + target + " was not rejected."); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/toStringTag/browser.js b/js/src/tests/test262/intl402/Collator/prototype/toStringTag/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/toStringTag/browser.js diff --git a/js/src/tests/test262/intl402/Collator/prototype/toStringTag/shell.js b/js/src/tests/test262/intl402/Collator/prototype/toStringTag/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/toStringTag/shell.js diff --git a/js/src/tests/test262/intl402/Collator/prototype/toStringTag/toString-changed-tag.js b/js/src/tests/test262/intl402/Collator/prototype/toStringTag/toString-changed-tag.js new file mode 100644 index 0000000000..84dcbda908 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/toStringTag/toString-changed-tag.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator.prototype-@@tostringtag +description: > + Object.prototype.toString utilizes Intl.Collator.prototype[@@toStringTag]. +info: | + Object.prototype.toString ( ) + + [...] + 14. Else, let builtinTag be "Object". + 15. Let tag be ? Get(O, @@toStringTag). + 16. If Type(tag) is not String, set tag to builtinTag. + 17. Return the string-concatenation of "[object ", tag, and "]". + + Intl.Collator.prototype [ @@toStringTag ] + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. +features: [Symbol.toStringTag] +---*/ + +Object.defineProperty(Intl.Collator.prototype, Symbol.toStringTag, { + value: "test262", +}); + +assert.sameValue(Object.prototype.toString.call(Intl.Collator.prototype), "[object test262]"); +assert.sameValue(Object.prototype.toString.call(new Intl.Collator()), "[object test262]"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/toStringTag/toString-removed-tag.js b/js/src/tests/test262/intl402/Collator/prototype/toStringTag/toString-removed-tag.js new file mode 100644 index 0000000000..16074d110f --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/toStringTag/toString-removed-tag.js @@ -0,0 +1,24 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator.prototype-@@tostringtag +description: > + Object.prototype.toString doesn't special-case neither Intl.Collator instances nor its prototype. +info: | + Object.prototype.toString ( ) + + [...] + 14. Else, let builtinTag be "Object". + 15. Let tag be ? Get(O, @@toStringTag). + 16. If Type(tag) is not String, set tag to builtinTag. + 17. Return the string-concatenation of "[object ", tag, and "]". +features: [Symbol.toStringTag] +---*/ + +delete Intl.Collator.prototype[Symbol.toStringTag]; + +assert.sameValue(Object.prototype.toString.call(Intl.Collator.prototype), "[object Object]"); +assert.sameValue(Object.prototype.toString.call(new Intl.Collator()), "[object Object]"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/toStringTag/toString.js b/js/src/tests/test262/intl402/Collator/prototype/toStringTag/toString.js new file mode 100644 index 0000000000..ad6395fee9 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/toStringTag/toString.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator.prototype-@@tostringtag +description: > + Object.prototype.toString utilizes Intl.Collator.prototype[@@toStringTag]. +info: | + Object.prototype.toString ( ) + + [...] + 14. Else, let builtinTag be "Object". + 15. Let tag be ? Get(O, @@toStringTag). + 16. If Type(tag) is not String, set tag to builtinTag. + 17. Return the string-concatenation of "[object ", tag, and "]". + + Intl.Collator.prototype [ @@toStringTag ] + + The initial value of the @@toStringTag property is the String value "Intl.Collator". +features: [Symbol.toStringTag] +---*/ + +assert.sameValue(Object.prototype.toString.call(Intl.Collator.prototype), "[object Intl.Collator]"); +assert.sameValue(Object.prototype.toString.call(new Intl.Collator()), "[object Intl.Collator]"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/prototype/toStringTag/toStringTag.js b/js/src/tests/test262/intl402/Collator/prototype/toStringTag/toStringTag.js new file mode 100644 index 0000000000..1f4942b46f --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/prototype/toStringTag/toStringTag.js @@ -0,0 +1,25 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator.prototype-@@tostringtag +description: > + Property descriptor of Intl.Collator.prototype[@@toStringTag]. +info: | + Intl.Collator.prototype [ @@toStringTag ] + + The initial value of the @@toStringTag property is the String value "Intl.Collator". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. +features: [Symbol.toStringTag] +includes: [propertyHelper.js] +---*/ + +verifyProperty(Intl.Collator.prototype, Symbol.toStringTag, { + value: "Intl.Collator", + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/shell.js b/js/src/tests/test262/intl402/Collator/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/shell.js diff --git a/js/src/tests/test262/intl402/Collator/subclassing.js b/js/src/tests/test262/intl402/Collator/subclassing.js new file mode 100644 index 0000000000..e6d499983d --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/subclassing.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. + +/*--- +es5id: 10.1.2_a +description: Tests that Intl.Collator can be subclassed. +author: Norbert Lindenberg +includes: [compareArray.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); + +class MyCollator extends Intl.Collator { + constructor(locales, options) { + super(locales, options); + // could initialize MyCollator properties + } + // could add methods to MyCollator.prototype +} + +var collator = new MyCollator(locales); +a.sort(collator.compare); +assert.compareArray(a, referenceSorted); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/supportedLocalesOf/basic.js b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/basic.js new file mode 100644 index 0000000000..4ec8ea705a --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/basic.js @@ -0,0 +1,24 @@ +// Copyright 2012 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 10.2.2_a +description: > + Tests that Intl.Collator has a supportedLocalesOf property, and + it works as planned. +---*/ + +var defaultLocale = new Intl.Collator().resolvedOptions().locale; +var notSupported = 'zxx'; // "no linguistic content" +var requestedLocales = [defaultLocale, notSupported]; + +var supportedLocales; + +assert(Intl.Collator.hasOwnProperty('supportedLocalesOf'), "Intl.Collator doesn't have a supportedLocalesOf property."); + +supportedLocales = Intl.Collator.supportedLocalesOf(requestedLocales); +assert.sameValue(supportedLocales.length, 1, 'The length of supported locales list is not 1.'); + +assert.sameValue(supportedLocales[0], defaultLocale, 'The default locale is not returned in the supported list.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/supportedLocalesOf/browser.js b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/browser.js diff --git a/js/src/tests/test262/intl402/Collator/supportedLocalesOf/builtin.js b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/builtin.js new file mode 100644 index 0000000000..ab5f0f3e3f --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/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: 10.2.2_L15 +description: > + Tests that Intl.Collator.supportedLocalesOf 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(Intl.Collator.supportedLocalesOf), "[object Function]", + "The [[Class]] internal property of a built-in function must be " + + "\"Function\"."); + +assert(Object.isExtensible(Intl.Collator.supportedLocalesOf), + "Built-in objects must be extensible."); + +assert.sameValue(Object.getPrototypeOf(Intl.Collator.supportedLocalesOf), Function.prototype); + +assert.sameValue(Intl.Collator.supportedLocalesOf.hasOwnProperty("prototype"), false, + "Built-in functions that aren't constructors must not have a prototype property."); + +assert.sameValue(isConstructor(Intl.Collator.supportedLocalesOf), false, + "Built-in functions don't implement [[Construct]] unless explicitly specified."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/supportedLocalesOf/length.js b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/length.js new file mode 100644 index 0000000000..086ed709d5 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator.supportedlocalesof +description: > + Intl.Collator.supportedLocalesOf.length is 1. +info: | + Intl.Collator.supportedLocalesOf ( 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] +---*/ + +assert.sameValue(Intl.Collator.supportedLocalesOf.length, 1); + +verifyNotEnumerable(Intl.Collator.supportedLocalesOf, "length"); +verifyNotWritable(Intl.Collator.supportedLocalesOf, "length"); +verifyConfigurable(Intl.Collator.supportedLocalesOf, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/supportedLocalesOf/name.js b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/name.js new file mode 100644 index 0000000000..471d0e9a6a --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.Collator.supportedLocalesOf +description: > + Intl.Collator.supportedLocalesOf.name is "supportedLocalesOf". +info: | + 10.2.2 Intl.Collator.supportedLocalesOf (locales [ , options ]) + + 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(Intl.Collator.supportedLocalesOf.name, "supportedLocalesOf"); + +verifyNotEnumerable(Intl.Collator.supportedLocalesOf, "name"); +verifyNotWritable(Intl.Collator.supportedLocalesOf, "name"); +verifyConfigurable(Intl.Collator.supportedLocalesOf, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/supportedLocalesOf/prop-desc.js b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/prop-desc.js new file mode 100644 index 0000000000..e47eb2fd80 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/prop-desc.js @@ -0,0 +1,31 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator.supportedlocalesof +description: > + "supportedLocalesOf" property of Intl.Collator. +info: | + Intl.Collator.supportedLocalesOf ( locales [ , options ] ) + + 7 Requirements for Standard Built-in ECMAScript Objects + + Unless specified otherwise in this document, the objects, functions, and constructors + described in this standard are subject to the generic requirements and restrictions + specified for standard built-in ECMAScript objects in the ECMAScript 2018 Language + Specification, 9th edition, clause 17, or successor. + + 17 ECMAScript Standard Built-in Objects: + + Every other data property described in clauses 18 through 26 and in Annex B.2 has the + attributes { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true } + unless otherwise specified. + +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(Intl.Collator, "supportedLocalesOf"); +verifyWritable(Intl.Collator, "supportedLocalesOf"); +verifyConfigurable(Intl.Collator, "supportedLocalesOf"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/supportedLocalesOf/shell.js b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/shell.js new file mode 100644 index 0000000000..54371b7789 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/shell.js @@ -0,0 +1,19 @@ +// 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] +---*/ + +function isConstructor(f) { + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/intl402/Collator/supportedLocalesOf/taint-Object-prototype.js b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/taint-Object-prototype.js new file mode 100644 index 0000000000..7e3018883f --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/supportedLocalesOf/taint-Object-prototype.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: 10.2.2_b +description: > + Tests that Intl.Collator.supportedLocalesOf doesn't access + arguments that it's not given. +author: Norbert Lindenberg +includes: [testIntl.js] +---*/ + +taintDataProperty(Object.prototype, "1"); +new Intl.Collator("und"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/taint-Object-prototype.js b/js/src/tests/test262/intl402/Collator/taint-Object-prototype.js new file mode 100644 index 0000000000..6832cb717d --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/taint-Object-prototype.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. + +/*--- +es5id: 10.1.1_10 +description: > + Tests that the behavior of a Record is not affected by + adversarial changes to Object.prototype. +author: Norbert Lindenberg +includes: [testIntl.js] +---*/ + +taintProperties(["localeMatcher", "kn", "kf"]); + +var locale = new Intl.Collator(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale; +assert(isCanonicalizedStructurallyValidLanguageTag(locale), "Collator returns invalid locale " + locale + "."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/test-option-ignorePunctuation.js b/js/src/tests/test262/intl402/Collator/test-option-ignorePunctuation.js new file mode 100644 index 0000000000..0ffdbb1fd0 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/test-option-ignorePunctuation.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. + +/*--- +es5id: 10.1.1_23 +description: Tests that the option ignorePunctuation is processed correctly. +author: Norbert Lindenberg +includes: [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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/test-option-localeMatcher.js b/js/src/tests/test262/intl402/Collator/test-option-localeMatcher.js new file mode 100644 index 0000000000..76492a09de --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/test-option-localeMatcher.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. + +/*--- +es5id: 10.1.1_11 +description: Tests that the option localeMatcher is processed correctly. +author: Norbert Lindenberg +includes: [testIntl.js] +---*/ + +testOption(Intl.Collator, "localeMatcher", "string", ["lookup", "best fit"], "best fit", {noReturn: true}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/test-option-numeric-and-caseFirst.js b/js/src/tests/test262/intl402/Collator/test-option-numeric-and-caseFirst.js new file mode 100644 index 0000000000..186c1b8410 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/test-option-numeric-and-caseFirst.js @@ -0,0 +1,16 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 10.1.1_13 +description: > + Tests that the options numeric and caseFirst are processed + correctly. +author: Norbert Lindenberg +includes: [testIntl.js] +---*/ + +testOption(Intl.Collator, "numeric", "boolean", undefined, undefined, {isOptional: true}); +testOption(Intl.Collator, "caseFirst", "string", ["upper", "lower", "false"], undefined, {isOptional: true}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/test-option-sensitivity.js b/js/src/tests/test262/intl402/Collator/test-option-sensitivity.js new file mode 100644 index 0000000000..382a6a84c4 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/test-option-sensitivity.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. + +/*--- +es5id: 10.1.1_20 +description: Tests that the option sensitivity is processed correctly. +author: Norbert Lindenberg +includes: [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"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/test-option-usage.js b/js/src/tests/test262/intl402/Collator/test-option-usage.js new file mode 100644 index 0000000000..d504c081e7 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/test-option-usage.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. + +/*--- +es5id: 10.1.1_6 +description: Tests that the option usage is processed correctly. +author: Norbert Lindenberg +includes: [testIntl.js] +---*/ + +testOption(Intl.Collator, "usage", "string", ["sort", "search"], "sort"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/this-value-ignored.js b/js/src/tests/test262/intl402/Collator/this-value-ignored.js new file mode 100644 index 0000000000..36286fbd66 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/this-value-ignored.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: 10.1.1_1 +description: Tests that the this-value is ignored in Collator. +author: Norbert Lindenberg +includes: [testIntl.js] +---*/ + +testWithIntlConstructors(function (Constructor) { + var obj, newObj; + + // variant 1: use constructor in a "new" expression + obj = new Constructor(); + newObj = Intl.Collator.call(obj); + assert.notSameValue(obj, newObj, "Collator object created with \"new\" was not ignored as this-value."); + + // variant 2: use constructor as a function + if (Constructor !== Intl.Collator && + Constructor !== Intl.NumberFormat && + Constructor !== Intl.DateTimeFormat) + { + // Newer Intl constructors are not callable as a function. + return; + } + obj = Constructor(); + newObj = Intl.Collator.call(obj); + assert.notSameValue(obj, newObj, "Collator object created with constructor as function was not ignored as this-value."); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/unicode-ext-seq-in-private-tag.js b/js/src/tests/test262/intl402/Collator/unicode-ext-seq-in-private-tag.js new file mode 100644 index 0000000000..2eb7546079 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/unicode-ext-seq-in-private-tag.js @@ -0,0 +1,29 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-initializecollator +description: > + Unicode extension sequence-like parts are ignored in private-use tags. +info: | + 10.1.1 InitializeCollator ( collator, locales, options ) + ... + 15. For each element key of relevantExtensionKeys in List order, do + a. If key is "co", then + i. Let value be r.[[co]]. + ii. If value is null, let value be "default". + iii. Set collator.[[Collation]] to value. + ... + + 10.3.5 Intl.Collator.prototype.resolvedOptions () + The function returns a new object whose properties and attributes are set as if constructed + by an object literal assigning to each of the following properties the value of the + corresponding internal slot of this Collator object (see 10.4): ... +---*/ + +var c = new Intl.Collator("de-x-u-co-phonebk"); +var resolved = c.resolvedOptions(); + +assert.sameValue(resolved.collation, "default"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/unicode-ext-seq-with-attribute.js b/js/src/tests/test262/intl402/Collator/unicode-ext-seq-with-attribute.js new file mode 100644 index 0000000000..6b03babc6e --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/unicode-ext-seq-with-attribute.js @@ -0,0 +1,33 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-initializecollator +description: > + Attributes in Unicode extension subtags should be ignored. +info: | + 10.1.1 InitializeCollator ( collator, locales, options ) + ... + 15. For each element key of relevantExtensionKeys in List order, do + a. If key is "co", then + i. Let value be r.[[co]]. + ii. If value is null, let value be "default". + iii. Set collator.[[Collation]] to value. + ... + + 10.3.5 Intl.Collator.prototype.resolvedOptions () + The function returns a new object whose properties and attributes are set as if constructed + by an object literal assigning to each of the following properties the value of the + corresponding internal slot of this Collator object (see 10.4): ... +---*/ + +var colExpected = new Intl.Collator("de-u-attrval-co-phonebk"); +var colActual = new Intl.Collator("de-u-co-phonebk"); + +var resolvedExpected = colExpected.resolvedOptions(); +var resolvedActual = colActual.resolvedOptions(); + +assert.sameValue(resolvedActual.locale, resolvedExpected.locale); +assert.sameValue(resolvedActual.collation, resolvedExpected.collation); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/unicode-ext-value-collation.js b/js/src/tests/test262/intl402/Collator/unicode-ext-value-collation.js new file mode 100644 index 0000000000..c09eefec32 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/unicode-ext-value-collation.js @@ -0,0 +1,40 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 10.1.1_19_b +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; + assert.notSameValue(expectedCollations.indexOf(collation), -1, (extensionCoValue === undefined ? "Default collation" : "Collation for \"" + extensionCoValue) + "\" should be " + expectedCollations.join(" or ") + ", but is " + collation + "."); + + var usage = collator.resolvedOptions().usage; + assert.sameValue(usage, expectedUsage, (usageValue === undefined ? "Default usage" : "Usage") + " mismatch."); +} + +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"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/Collator/usage-de.js b/js/src/tests/test262/intl402/Collator/usage-de.js new file mode 100644 index 0000000000..e0b01f5db6 --- /dev/null +++ b/js/src/tests/test262/intl402/Collator/usage-de.js @@ -0,0 +1,18 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-initializecollator +description: Checks the behavior of search and sort in German. +includes: [compareArray.js] +locale: [de] +---*/ + +assert.compareArray(["AE", "\u00C4"].sort(new Intl.Collator("de", {usage: "sort"}).compare), + ["\u00C4", "AE"], + "sort"); +assert.compareArray(["AE", "\u00C4"].sort(new Intl.Collator("de", {usage: "search"}).compare), + ["AE", "\u00C4"], + "search"); + +reportCompare(0, 0); |