diff options
Diffstat (limited to 'test/suite/intl402/ch10/10.3')
-rw-r--r-- | test/suite/intl402/ch10/10.3/10.3.2_1_c.js | 36 | ||||
-rw-r--r-- | test/suite/intl402/ch10/10.3/10.3.2_CS_a.js | 56 | ||||
-rw-r--r-- | test/suite/intl402/ch10/10.3/10.3.2_CS_b_NN.js | 22 | ||||
-rw-r--r-- | test/suite/intl402/ch10/10.3/10.3.2_CS_c_NN.js | 22 | ||||
-rw-r--r-- | test/suite/intl402/ch10/10.3/10.3.2_CS_d_NN.js | 34 | ||||
-rw-r--r-- | test/suite/intl402/ch10/10.3/10.3.3.js | 48 | ||||
-rw-r--r-- | test/suite/intl402/ch10/10.3/10.3_a.js (renamed from test/suite/intl402/ch10/10.3/10.3.js) | 0 | ||||
-rw-r--r-- | test/suite/intl402/ch10/10.3/10.3_b.js | 33 |
8 files changed, 251 insertions, 0 deletions
diff --git a/test/suite/intl402/ch10/10.3/10.3.2_1_c.js b/test/suite/intl402/ch10/10.3/10.3.2_1_c.js new file mode 100644 index 000000000..077961266 --- /dev/null +++ b/test/suite/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.", "\uD842\uDFB7野家", "吉野家", "!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/test/suite/intl402/ch10/10.3/10.3.2_CS_a.js b/test/suite/intl402/ch10/10.3/10.3.2_CS_a.js new file mode 100644 index 000000000..88e3cdb87 --- /dev/null +++ b/test/suite/intl402/ch10/10.3/10.3.2_CS_a.js @@ -0,0 +1,56 @@ +// 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] + " ≠ " + pair[1] + "."); + } +} + diff --git a/test/suite/intl402/ch10/10.3/10.3.2_CS_b_NN.js b/test/suite/intl402/ch10/10.3/10.3.2_CS_b_NN.js new file mode 100644 index 000000000..c417d2b8a --- /dev/null +++ b/test/suite/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/test/suite/intl402/ch10/10.3/10.3.2_CS_c_NN.js b/test/suite/intl402/ch10/10.3/10.3.2_CS_c_NN.js new file mode 100644 index 000000000..5d5060be5 --- /dev/null +++ b/test/suite/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/test/suite/intl402/ch10/10.3/10.3.2_CS_d_NN.js b/test/suite/intl402/ch10/10.3/10.3.2_CS_d_NN.js new file mode 100644 index 000000000..be5f1aa33 --- /dev/null +++ b/test/suite/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/test/suite/intl402/ch10/10.3/10.3.3.js b/test/suite/intl402/ch10/10.3/10.3.3.js new file mode 100644 index 000000000..56c294491 --- /dev/null +++ b/test/suite/intl402/ch10/10.3/10.3.3.js @@ -0,0 +1,48 @@ +// 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, "normalization", [true, false]); +mayHaveProperty(actual, "caseFirst", ["upper", "lower", "false"]); + diff --git a/test/suite/intl402/ch10/10.3/10.3.js b/test/suite/intl402/ch10/10.3/10.3_a.js index aa2e52845..aa2e52845 100644 --- a/test/suite/intl402/ch10/10.3/10.3.js +++ b/test/suite/intl402/ch10/10.3/10.3_a.js diff --git a/test/suite/intl402/ch10/10.3/10.3_b.js b/test/suite/intl402/ch10/10.3/10.3_b.js new file mode 100644 index 000000000..9c3c2db32 --- /dev/null +++ b/test/suite/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 + "."); + } + }); +}); + |