michael@0: // Copyright 2012 Norbert Lindenberg. All rights reserved. michael@0: // Copyright 2012 Mozilla Corporation. All rights reserved. michael@0: // This code is governed by the license found in the LICENSE file. michael@0: michael@0: /** michael@0: * @description Tests that the function returned by Intl.Collator.prototype.compare michael@0: * returns 0 when comparing Strings that are considered canonically equivalent michael@0: * by the Unicode standard. michael@0: * @author Norbert Lindenberg michael@0: */ michael@0: michael@0: var collator = new Intl.Collator(); michael@0: var pairs = [ michael@0: // example from Unicode 5.0, section 3.7, definition D70 michael@0: ["o\u0308", "ö"], michael@0: // examples from Unicode 5.0, chapter 3.11 michael@0: ["ä\u0323", "a\u0323\u0308"], michael@0: ["a\u0308\u0323", "a\u0323\u0308"], michael@0: ["ạ\u0308", "a\u0323\u0308"], michael@0: ["ä\u0306", "a\u0308\u0306"], michael@0: ["ă\u0308", "a\u0306\u0308"], michael@0: // example from Unicode 5.0, chapter 3.12 michael@0: ["\u1111\u1171\u11B6", "퓛"], michael@0: // examples from UTS 10, Unicode Collation Algorithm michael@0: ["Å", "Å"], michael@0: ["Å", "A\u030A"], michael@0: ["x\u031B\u0323", "x\u0323\u031B"], michael@0: ["ự", "ụ\u031B"], michael@0: ["ự", "u\u031B\u0323"], michael@0: ["ự", "ư\u0323"], michael@0: ["ự", "u\u0323\u031B"], michael@0: // examples from UAX 15, Unicode Normalization Forms michael@0: ["Ç", "C\u0327"], michael@0: ["q\u0307\u0323", "q\u0323\u0307"], michael@0: ["가", "\u1100\u1161"], michael@0: ["Å", "A\u030A"], michael@0: ["Ω", "Ω"], michael@0: ["Å", "A\u030A"], michael@0: ["ô", "o\u0302"], michael@0: ["ṩ", "s\u0323\u0307"], michael@0: ["ḋ\u0323", "d\u0323\u0307"], michael@0: ["ḋ\u0323", "ḍ\u0307"], michael@0: ["q\u0307\u0323", "q\u0323\u0307"], michael@0: // examples involving supplementary characters from UCD NormalizationTest.txt michael@0: ["\uD834\uDD5E", "\uD834\uDD57\uD834\uDD65"], michael@0: ["\uD87E\uDC2B", "北"] michael@0: michael@0: ]; michael@0: var i; michael@0: for (i = 0; i < pairs.length; i++) { michael@0: var pair = pairs[i]; michael@0: if (collator.compare(pair[0], pair[1]) !== 0) { michael@0: $ERROR("Collator.compare considers " + pair[0] + " (" + toU(pair[0]) + michael@0: ") ≠ " + pair[1] + " (" + toU(pair[1]) + ")."); michael@0: } michael@0: } michael@0: michael@0: function toU(s) { michael@0: var result = ""; michael@0: var escape = "\\u0000"; michael@0: var i; michael@0: for (i = 0; i < s.length; i++) { michael@0: var hex = s.charCodeAt(i).toString(16); michael@0: result += escape.substring(0, escape.length - hex.length) + hex; michael@0: } michael@0: return result; michael@0: } michael@0: