diff options
Diffstat (limited to 'js/src/tests/test262/intl402/ch10')
43 files changed, 818 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/ch10/10.1/10.1.1_1.js b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_1.js new file mode 100644 index 000000000..432e073fc --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_1.js @@ -0,0 +1,43 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that an object can't be re-initialized as a Collator. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +testWithIntlConstructors(function (Constructor) { + var obj, error; + + // variant 1: use constructor in a "new" expression + obj = new Constructor(); + try { + Intl.Collator.call(obj); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Re-initializing object created with \"new\" as Collator was not rejected."); + } else if (error.name !== "TypeError") { + $ERROR("Re-initializing object created with \"new\" as Collator was rejected with wrong error " + error.name + "."); + } + + // variant 2: use constructor as a function + obj = Constructor.call({}); + error = undefined; + try { + Intl.Collator.call(obj); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Re-initializing object created with constructor as function as Collator was not rejected."); + } else if (error.name !== "TypeError") { + $ERROR("Re-initializing object created with constructor as function as Collator was rejected with wrong error " + error.name + "."); + } + + return true; +}); + diff --git a/js/src/tests/test262/intl402/ch10/10.1/10.1.1_10.js b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_10.js new file mode 100644 index 000000000..5c6b657b5 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_10.js @@ -0,0 +1,18 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the behavior of a Record is not affected by adversarial + * changes to Object.prototype. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +taintProperties(["localeMatcher", "kn", "kf"]); + +var locale = new Intl.Collator(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale; +if (!isCanonicalizedStructurallyValidLanguageTag(locale)) { + $ERROR("Collator returns invalid locale " + locale + "."); +} + diff --git a/js/src/tests/test262/intl402/ch10/10.1/10.1.1_11.js b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_11.js new file mode 100644 index 000000000..447fd8b28 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_11.js @@ -0,0 +1,12 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the option localeMatcher is processed correctly. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +testOption(Intl.Collator, "localeMatcher", "string", ["lookup", "best fit"], "best fit", {noReturn: true}); + diff --git a/js/src/tests/test262/intl402/ch10/10.1/10.1.1_13.js b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_13.js new file mode 100644 index 000000000..4129eebd2 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_13.js @@ -0,0 +1,13 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the options numeric and caseFirst are processed correctly. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +testOption(Intl.Collator, "numeric", "boolean", undefined, undefined, {isOptional: true}); +testOption(Intl.Collator, "caseFirst", "string", ["upper", "lower", "false"], undefined, {isOptional: true}); + diff --git a/js/src/tests/test262/intl402/ch10/10.1/10.1.1_19_b.js b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_19_b.js new file mode 100644 index 000000000..f1fef2704 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_19_b.js @@ -0,0 +1,44 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests the special handling of the "co" key in Intl.Collator. + * @author Norbert Lindenberg + */ + +function checkCollation(extensionCoValue, usageValue, expectedCollations, expectedUsage) { + var requestLocale = extensionCoValue !== undefined ? "de-DE-u-co-" + extensionCoValue : "de-DE"; + var options = usageValue !== undefined ? { usage: usageValue } : undefined; + var collator = new Intl.Collator([requestLocale], options); + + var collation = collator.resolvedOptions().collation; + if (expectedCollations.indexOf(collation) === -1) { + $ERROR((extensionCoValue === undefined ? "Default collation" : "Collation for \"" + extensionCoValue) + + "\" should be " + expectedCollations.join(" or ") + ", but is " + collation + "."); + } + + var usage = collator.resolvedOptions().usage; + if (expectedUsage !== usage) { + $ERROR((usageValue === undefined ? "Default usage" : "Usage") + + " should be " + expectedUsage + ", but is " + usage + "."); + } +} + +checkCollation(undefined, undefined, ["default"], "sort"); + +checkCollation("phonebk", undefined, ["phonebk", "default"], "sort"); + +checkCollation("invalid", undefined, ["default"], "sort"); + +checkCollation("standard", undefined, ["default"], "sort"); + +checkCollation("standard", "search", ["default"], "search"); + +checkCollation("standard", "sort", ["default"], "sort"); + +checkCollation("search", undefined, ["default"], "sort"); + +checkCollation("search", "search", ["default"], "search"); + +checkCollation("search", "sort", ["default"], "sort"); + diff --git a/js/src/tests/test262/intl402/ch10/10.1/10.1.1_19_c.js b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_19_c.js new file mode 100644 index 000000000..4ad76d45b --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_19_c.js @@ -0,0 +1,63 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the options numeric and caseFirst can be + * set through either the locale or the options. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var options = [ + {key: "kn", property: "numeric", type: "boolean", values: [true, false]}, + {key: "kf", property: "caseFirst", type: "string", values: ["upper", "lower", "false"]} +]; + +options.forEach(function (option) { + var defaultLocale = new Intl.Collator().resolvedOptions().locale; + var collator, opt, result; + + // find out which values are supported for a property in the default locale + var supportedValues = []; + option.values.forEach(function (value) { + opt = {}; + opt[option.property] = value; + collator = new Intl.Collator([defaultLocale], opt); + result = collator.resolvedOptions()[option.property]; + if (result !== undefined && supportedValues.indexOf(result) === -1) { + supportedValues.push(result); + } + }); + + // verify that the supported values can also be set through the locale + supportedValues.forEach(function (value) { + collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + value]); + result = collator.resolvedOptions()[option.property]; + if (result !== value) { + $ERROR("Property " + option.property + " couldn't be set through locale extension key " + + option.key + "; requested value: " + value + "; actual value: " + result + "."); + } + }); + + // verify that the options setting overrides the locale setting + supportedValues.forEach(function (value) { + var otherValue; + option.values.forEach(function (possibleValue) { + if (possibleValue !== value) { + otherValue = possibleValue; + } + }); + if (otherValue !== undefined) { + opt = {}; + opt[option.property] = value; + collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + otherValue], opt); + result = collator.resolvedOptions()[option.property]; + if (result !== value) { + $ERROR("Options value for property " + option.property + " doesn't override locale extension key " + + option.key + "; requested value: " + value + "; actual value: " + result + "."); + } + } + }); +}); + diff --git a/js/src/tests/test262/intl402/ch10/10.1/10.1.1_20.js b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_20.js new file mode 100644 index 000000000..97d70c0f9 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_20.js @@ -0,0 +1,13 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the option sensitivity is processed correctly. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +// the fallback is variant only for usage === sort, but that happens to be the fallback for usage +testOption(Intl.Collator, "sensitivity", "string", ["base", "accent", "case", "variant"], "variant"); + diff --git a/js/src/tests/test262/intl402/ch10/10.1/10.1.1_23.js b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_23.js new file mode 100644 index 000000000..0b5261509 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_23.js @@ -0,0 +1,13 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the option ignorePunctuation is processed correctly. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +// the fallback is variant only for usage === sort, but that happens to be the fallback for usage +testOption(Intl.Collator, "ignorePunctuation", "boolean", undefined, false); + diff --git a/js/src/tests/test262/intl402/ch10/10.1/10.1.1_6.js b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_6.js new file mode 100644 index 000000000..bc13436d7 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_6.js @@ -0,0 +1,12 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the option usage is processed correctly. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +testOption(Intl.Collator, "usage", "string", ["sort", "search"], "sort"); + diff --git a/js/src/tests/test262/intl402/ch10/10.1/10.1.1_a.js b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_a.js new file mode 100644 index 000000000..56d4b9789 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/10.1.1_a.js @@ -0,0 +1,14 @@ +// Copyright 2013 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that constructing a Collator doesn't create or modify + * unwanted properties on the RegExp constructor. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +testForUnwantedRegExpChanges(function () { + new Intl.Collator("de-DE-u-co-phonebk"); +}); diff --git a/js/src/tests/test262/intl402/ch10/10.1/10.1.2.1_4.js b/js/src/tests/test262/intl402/ch10/10.1/10.1.2.1_4.js new file mode 100644 index 000000000..22e69065e --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/10.1.2.1_4.js @@ -0,0 +1,21 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that for non-object values passed as this to Collator a + * wrapper object will be initialized and returned. + * @author Norbert Lindenberg + */ + +var thisValues = [true, 42, "国際化"]; + +thisValues.forEach(function (value) { + var collator = Intl.Collator.call(value); + // check that the returned object functions as a collator + var referenceCollator = new Intl.Collator(); + if (Intl.Collator.prototype.compare.call(collator, "a", "b") !== referenceCollator.compare("a", "b")) { + $ERROR("Collator initialized from " + value + " doesn't behave like normal collator."); + } + return true; +}); + diff --git a/js/src/tests/test262/intl402/ch10/10.1/10.1.2_a.js b/js/src/tests/test262/intl402/ch10/10.1/10.1.2_a.js new file mode 100644 index 000000000..de69a4809 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/10.1.2_a.js @@ -0,0 +1,30 @@ +// Copyright 2011-2012 Norbert Lindenberg. All rights reserved. +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Intl.Collator can be subclassed. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +// get a collator and have it sort an array for comparison with the subclass +var locales = ["tlh", "id", "en"]; +var a = ["A", "C", "E", "B", "D", "F"]; +var referenceCollator = new Intl.Collator(locales); +var referenceSorted = a.slice().sort(referenceCollator.compare); + +function MyCollator(locales, options) { + Intl.Collator.call(this, locales, options); + // could initialize MyCollator properties +} + +MyCollator.prototype = Object.create(Intl.Collator.prototype); +MyCollator.prototype.constructor = MyCollator; +// could add methods to MyCollator.prototype + +var collator = new MyCollator(locales); +a.sort(collator.compare); +testArraysAreSame(referenceSorted, a); + diff --git a/js/src/tests/test262/intl402/ch10/10.1/10.1.3.js b/js/src/tests/test262/intl402/ch10/10.1/10.1.3.js new file mode 100644 index 000000000..7459d98d6 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/10.1.3.js @@ -0,0 +1,19 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that objects constructed by Intl.Collator have the specified internal properties. + * @author Norbert Lindenberg + */ + +var obj = new Intl.Collator(); + +var actualPrototype = Object.getPrototypeOf(obj); +if (actualPrototype !== Intl.Collator.prototype) { + $ERROR("Prototype of object constructed by Intl.Collator isn't Intl.Collator.prototype; got " + actualPrototype); +} + +if (!Object.isExtensible(obj)) { + $ERROR("Object constructed by Intl.Collator must be extensible."); +} + diff --git a/js/src/tests/test262/intl402/ch10/10.1/10.1_L15.js b/js/src/tests/test262/intl402/ch10/10.1/10.1_L15.js new file mode 100644 index 000000000..4dbabfd64 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/10.1_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Intl.Collator + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(Intl.Collator, true, true, ["supportedLocalesOf"], 0); + diff --git a/js/src/tests/test262/intl402/ch10/10.1/browser.js b/js/src/tests/test262/intl402/ch10/10.1/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/browser.js diff --git a/js/src/tests/test262/intl402/ch10/10.1/shell.js b/js/src/tests/test262/intl402/ch10/10.1/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.1/shell.js diff --git a/js/src/tests/test262/intl402/ch10/10.2/10.2.1.js b/js/src/tests/test262/intl402/ch10/10.2/10.2.1.js new file mode 100644 index 000000000..9eccb073c --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.2/10.2.1.js @@ -0,0 +1,22 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Intl.Collator.prototype has the required attributes. + * @author Norbert Lindenberg + */ + +var desc = Object.getOwnPropertyDescriptor(Intl.Collator, "prototype"); +if (desc === undefined) { + $ERROR("Intl.Collator.prototype is not defined."); +} +if (desc.writable) { + $ERROR("Intl.Collator.prototype must not be writable."); +} +if (desc.enumerable) { + $ERROR("Intl.Collator.prototype must not be enumerable."); +} +if (desc.configurable) { + $ERROR("Intl.Collator.prototype must not be configurable."); +} + diff --git a/js/src/tests/test262/intl402/ch10/10.2/10.2.2_L15.js b/js/src/tests/test262/intl402/ch10/10.2/10.2.2_L15.js new file mode 100644 index 000000000..6ffcdde84 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.2/10.2.2_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Intl.Collator.supportedLocalesOf + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(Intl.Collator.supportedLocalesOf, true, false, [], 1); + diff --git a/js/src/tests/test262/intl402/ch10/10.2/10.2.2_a.js b/js/src/tests/test262/intl402/ch10/10.2/10.2.2_a.js new file mode 100644 index 000000000..5cf953ce8 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.2/10.2.2_a.js @@ -0,0 +1,27 @@ +// Copyright 2012 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @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; + +if (!Intl.Collator.hasOwnProperty('supportedLocalesOf')) { + $ERROR("Intl.Collator doesn't have a supportedLocalesOf property."); +} + +supportedLocales = Intl.Collator.supportedLocalesOf(requestedLocales); +if (supportedLocales.length !== 1) { + $ERROR('The length of supported locales list is not 1.'); +} + +if (supportedLocales[0] !== defaultLocale) { + $ERROR('The default locale is not returned in the supported list.'); +} + diff --git a/js/src/tests/test262/intl402/ch10/10.2/10.2.2_b.js b/js/src/tests/test262/intl402/ch10/10.2/10.2.2_b.js new file mode 100644 index 000000000..1b99fd8c5 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.2/10.2.2_b.js @@ -0,0 +1,13 @@ +// Copyright 2013 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Intl.Collator.supportedLocalesOf + * doesn't access arguments that it's not given. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +taintDataProperty(Object.prototype, "1"); +new Intl.Collator("und"); diff --git a/js/src/tests/test262/intl402/ch10/10.2/10.2.3_b.js b/js/src/tests/test262/intl402/ch10/10.2/10.2.3_b.js new file mode 100644 index 000000000..aef1e746a --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.2/10.2.3_b.js @@ -0,0 +1,52 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Intl.Collator does not accept Unicode locale + * extension keys and values that are not allowed. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.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(); + if (options.locale !== defaultLocale) { + $ERROR("Locale " + options.locale + " is affected by key " + + key + "; value " + value + "."); + } + if (JSON.stringify(options) !== defaultOptionsJSON) { + $ERROR("Resolved options " + JSON.stringify(options) + " are affected by key " + + key + "; value " + value + "."); + } + testArraysAreSame(defaultSortedArray, testArray.sort(collator.compare)); + }); +}); + diff --git a/js/src/tests/test262/intl402/ch10/10.2/browser.js b/js/src/tests/test262/intl402/ch10/10.2/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.2/browser.js diff --git a/js/src/tests/test262/intl402/ch10/10.2/shell.js b/js/src/tests/test262/intl402/ch10/10.2/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.2/shell.js diff --git a/js/src/tests/test262/intl402/ch10/10.3/10.3.1.js b/js/src/tests/test262/intl402/ch10/10.3/10.3.1.js new file mode 100644 index 000000000..699949e18 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.3/10.3.1.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. + +/** + * @description Tests that Intl.Collator.prototype.constructor is the + * Intl.Collator. + */ + +if (Intl.Collator.prototype.constructor !== Intl.Collator) { + $ERROR("Intl.Collator.prototype.constructor is not the same as " + + "Intl.Collator"); +} + diff --git a/js/src/tests/test262/intl402/ch10/10.3/10.3.2_1_a_L15.js b/js/src/tests/test262/intl402/ch10/10.3/10.3.2_1_a_L15.js new file mode 100644 index 000000000..3d49601db --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.3/10.3.2_1_a_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that the function returned by Intl.Collator.prototype.compare + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(new Intl.Collator().compare, true, false, [], 2); + diff --git a/js/src/tests/test262/intl402/ch10/10.3/10.3.2_1_c.js b/js/src/tests/test262/intl402/ch10/10.3/10.3.2_1_c.js new file mode 100644 index 000000000..73f2bcf09 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.3/10.3.2_1_c.js @@ -0,0 +1,36 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that compare function is bound to its Intl.Collator. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var strings = ["d", "O", "od", "oe", "of", "ö", "o\u0308", "X", "y", "Z", "Z.", "𠮷野家", "吉野家", "!A", "A", "b", "C"]; +var locales = [undefined, ["de"], ["de-u-co-phonebk"], ["en"], ["ja"], ["sv"]]; +var options = [ + undefined, + {usage: "search"}, + {sensitivity: "base", ignorePunctuation: true} +]; + +locales.forEach(function (locales) { + options.forEach(function (options) { + var 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); + try { + testArraysAreSame(referenceSorted, sorted); + } catch (e) { + e.message += " (Testing with locales " + locales + "; options " + + (options ? JSON.stringify(options) : options) + ".)"; + throw e; + } + }); +}); + diff --git a/js/src/tests/test262/intl402/ch10/10.3/10.3.2_CS_a.js b/js/src/tests/test262/intl402/ch10/10.3/10.3.2_CS_a.js new file mode 100644 index 000000000..a946245b4 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.3/10.3.2_CS_a.js @@ -0,0 +1,68 @@ +// 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. + +/** + * @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]; + if (collator.compare(pair[0], pair[1]) !== 0) { + $ERROR("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; +} + diff --git a/js/src/tests/test262/intl402/ch10/10.3/10.3.2_CS_b_NN.js b/js/src/tests/test262/intl402/ch10/10.3/10.3.2_CS_b_NN.js new file mode 100644 index 000000000..c417d2b8a --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.3/10.3.2_CS_b_NN.js @@ -0,0 +1,22 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the compare function isn't entirely unreasonable. + * This test is not normative. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.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"]; + testArraysAreSame(expected, a); +}); + diff --git a/js/src/tests/test262/intl402/ch10/10.3/10.3.2_CS_c_NN.js b/js/src/tests/test262/intl402/ch10/10.3/10.3.2_CS_c_NN.js new file mode 100644 index 000000000..5d5060be5 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.3/10.3.2_CS_c_NN.js @@ -0,0 +1,22 @@ +// Copyright 2011-2012 Norbert Lindenberg. All rights reserved. +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the compare function supports phonebook sorting if it says it does. + * This test is not normative. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.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"]; + testArraysAreSame(expected, a); +} + diff --git a/js/src/tests/test262/intl402/ch10/10.3/10.3.2_CS_d_NN.js b/js/src/tests/test262/intl402/ch10/10.3/10.3.2_CS_d_NN.js new file mode 100644 index 000000000..be5f1aa33 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.3/10.3.2_CS_d_NN.js @@ -0,0 +1,34 @@ +// Copyright 2011-2012 Norbert Lindenberg. All rights reserved. +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the compare function supports different sensitivity settings. + * This test is not normative. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.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; + }); + testArraysAreSame(expected[sensitivity], matches); + }); +}); + diff --git a/js/src/tests/test262/intl402/ch10/10.3/10.3.2_L15.js b/js/src/tests/test262/intl402/ch10/10.3/10.3.2_L15.js new file mode 100644 index 000000000..5845ea3ca --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.3/10.3.2_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that the getter for Intl.Collator.prototype.compare + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(Object.getOwnPropertyDescriptor(Intl.Collator.prototype, "compare").get , true, false, [], 0); + diff --git a/js/src/tests/test262/intl402/ch10/10.3/10.3.3.js b/js/src/tests/test262/intl402/ch10/10.3/10.3.3.js new file mode 100644 index 000000000..bc6b4fabb --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.3/10.3.3.js @@ -0,0 +1,47 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that the object returned by Intl.Collator.prototype.resolvedOptions + * has the right properties. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var actual = new Intl.Collator().resolvedOptions(); + +var actual2 = new Intl.Collator().resolvedOptions(); +if (actual2 === actual) { + $ERROR("resolvedOptions returned the same object twice."); +} + +// source: CLDR file common/bcp47/collation.xml; version CLDR 21. +var collations = [ + "default", // added + "big5han", + "dict", + "direct", + "ducet", + "gb2312", + "phonebk", + "phonetic", + "pinyin", + "reformed", + // "search", // excluded + "searchjl", + // "standard", // excluded + "stroke", + "trad", + "unihan" +]; + +// this assumes the default values where the specification provides them +mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag); +mustHaveProperty(actual, "usage", ["sort"]); +mustHaveProperty(actual, "sensitivity", ["variant"]); +mustHaveProperty(actual, "ignorePunctuation", [false]); +mustHaveProperty(actual, "collation", collations); +mayHaveProperty(actual, "numeric", [true, false]); +mayHaveProperty(actual, "caseFirst", ["upper", "lower", "false"]); + diff --git a/js/src/tests/test262/intl402/ch10/10.3/10.3.3_L15.js b/js/src/tests/test262/intl402/ch10/10.3/10.3.3_L15.js new file mode 100644 index 000000000..718cc9fea --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.3/10.3.3_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Intl.Collator.prototype.resolvedOptions + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(Intl.Collator.prototype.resolvedOptions, true, false, [], 0); + diff --git a/js/src/tests/test262/intl402/ch10/10.3/10.3_L15.js b/js/src/tests/test262/intl402/ch10/10.3/10.3_L15.js new file mode 100644 index 000000000..60719736c --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.3/10.3_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Intl.Collator.prototype + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(Intl.Collator.prototype, false, false, ["constructor", "compare", "resolvedOptions"]); + diff --git a/js/src/tests/test262/intl402/ch10/10.3/10.3_a.js b/js/src/tests/test262/intl402/ch10/10.3/10.3_a.js new file mode 100644 index 000000000..aa2e52845 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.3/10.3_a.js @@ -0,0 +1,15 @@ +// Copyright 2012 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Intl.Collator.prototype is an object that + * has been initialized as an Intl.Collator. + */ + +// test by calling a function that would fail if "this" were not an object +// initialized as an Intl.Collator +if (Intl.Collator.prototype.compare("aаあ아", "aаあ아") !== 0) { + $ERROR("Intl.Collator.prototype is not an object that has been " + + "initialized as an Intl.Collator."); +} + diff --git a/js/src/tests/test262/intl402/ch10/10.3/10.3_b.js b/js/src/tests/test262/intl402/ch10/10.3/10.3_b.js new file mode 100644 index 000000000..9c3c2db32 --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.3/10.3_b.js @@ -0,0 +1,33 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that 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) { + var error; + try { + f.call(target); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Calling " + functionName + " on " + target + " was not rejected."); + } else if (error.name !== "TypeError") { + $ERROR("Calling " + functionName + " on " + target + " was rejected with wrong error " + error.name + "."); + } + }); +}); + diff --git a/js/src/tests/test262/intl402/ch10/10.3/browser.js b/js/src/tests/test262/intl402/ch10/10.3/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.3/browser.js diff --git a/js/src/tests/test262/intl402/ch10/10.3/shell.js b/js/src/tests/test262/intl402/ch10/10.3/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.3/shell.js diff --git a/js/src/tests/test262/intl402/ch10/10.4/10.4_a.js b/js/src/tests/test262/intl402/ch10/10.4/10.4_a.js new file mode 100644 index 000000000..7527f65eb --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.4/10.4_a.js @@ -0,0 +1,15 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Intl.Collator instances have the specified properties. + * @author Norbert Lindenberg + */ + +var obj = new Intl.Collator(); + +var toStringValue = Object.prototype.toString.call(obj); +if (toStringValue !== "[object Object]") { + $ERROR("Intl.Collator instance produces wrong [[Class]] - toString returns " + toStringValue + "."); +} + diff --git a/js/src/tests/test262/intl402/ch10/10.4/browser.js b/js/src/tests/test262/intl402/ch10/10.4/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.4/browser.js diff --git a/js/src/tests/test262/intl402/ch10/10.4/shell.js b/js/src/tests/test262/intl402/ch10/10.4/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/10.4/shell.js diff --git a/js/src/tests/test262/intl402/ch10/browser.js b/js/src/tests/test262/intl402/ch10/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/browser.js diff --git a/js/src/tests/test262/intl402/ch10/shell.js b/js/src/tests/test262/intl402/ch10/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch10/shell.js |