js/src/tests/test262/intl402/ch10/10.3/10.3.2_CS_a.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 // Copyright 2012 Norbert Lindenberg. All rights reserved.
michael@0 2 // Copyright 2012 Mozilla Corporation. All rights reserved.
michael@0 3 // This code is governed by the license found in the LICENSE file.
michael@0 4
michael@0 5 /**
michael@0 6 * @description Tests that the function returned by Intl.Collator.prototype.compare
michael@0 7 * returns 0 when comparing Strings that are considered canonically equivalent
michael@0 8 * by the Unicode standard.
michael@0 9 * @author Norbert Lindenberg
michael@0 10 */
michael@0 11
michael@0 12 var collator = new Intl.Collator();
michael@0 13 var pairs = [
michael@0 14 // example from Unicode 5.0, section 3.7, definition D70
michael@0 15 ["o\u0308", "ö"],
michael@0 16 // examples from Unicode 5.0, chapter 3.11
michael@0 17 ["ä\u0323", "a\u0323\u0308"],
michael@0 18 ["a\u0308\u0323", "a\u0323\u0308"],
michael@0 19 ["ạ\u0308", "a\u0323\u0308"],
michael@0 20 ["ä\u0306", "a\u0308\u0306"],
michael@0 21 ["ă\u0308", "a\u0306\u0308"],
michael@0 22 // example from Unicode 5.0, chapter 3.12
michael@0 23 ["\u1111\u1171\u11B6", "퓛"],
michael@0 24 // examples from UTS 10, Unicode Collation Algorithm
michael@0 25 ["Å", "Å"],
michael@0 26 ["Å", "A\u030A"],
michael@0 27 ["x\u031B\u0323", "x\u0323\u031B"],
michael@0 28 ["ự", "ụ\u031B"],
michael@0 29 ["ự", "u\u031B\u0323"],
michael@0 30 ["ự", "ư\u0323"],
michael@0 31 ["ự", "u\u0323\u031B"],
michael@0 32 // examples from UAX 15, Unicode Normalization Forms
michael@0 33 ["Ç", "C\u0327"],
michael@0 34 ["q\u0307\u0323", "q\u0323\u0307"],
michael@0 35 ["가", "\u1100\u1161"],
michael@0 36 ["Å", "A\u030A"],
michael@0 37 ["Ω", "Ω"],
michael@0 38 ["Å", "A\u030A"],
michael@0 39 ["ô", "o\u0302"],
michael@0 40 ["ṩ", "s\u0323\u0307"],
michael@0 41 ["ḋ\u0323", "d\u0323\u0307"],
michael@0 42 ["ḋ\u0323", "ḍ\u0307"],
michael@0 43 ["q\u0307\u0323", "q\u0323\u0307"],
michael@0 44 // examples involving supplementary characters from UCD NormalizationTest.txt
michael@0 45 ["\uD834\uDD5E", "\uD834\uDD57\uD834\uDD65"],
michael@0 46 ["\uD87E\uDC2B", "北"]
michael@0 47
michael@0 48 ];
michael@0 49 var i;
michael@0 50 for (i = 0; i < pairs.length; i++) {
michael@0 51 var pair = pairs[i];
michael@0 52 if (collator.compare(pair[0], pair[1]) !== 0) {
michael@0 53 $ERROR("Collator.compare considers " + pair[0] + " (" + toU(pair[0]) +
michael@0 54 ") ≠ " + pair[1] + " (" + toU(pair[1]) + ").");
michael@0 55 }
michael@0 56 }
michael@0 57
michael@0 58 function toU(s) {
michael@0 59 var result = "";
michael@0 60 var escape = "\\u0000";
michael@0 61 var i;
michael@0 62 for (i = 0; i < s.length; i++) {
michael@0 63 var hex = s.charCodeAt(i).toString(16);
michael@0 64 result += escape.substring(0, escape.length - hex.length) + hex;
michael@0 65 }
michael@0 66 return result;
michael@0 67 }
michael@0 68

mercurial