michael@0: // Copyright 2012 Mozilla Corporation. All rights reserved. michael@0: // This code is governed by the BSD license found in the LICENSE file. michael@0: michael@0: /** michael@0: * @description Tests that compare function is bound to its Intl.Collator. michael@0: * @author Norbert Lindenberg michael@0: */ michael@0: michael@0: $INCLUDE("testIntl.js"); michael@0: michael@0: var strings = ["d", "O", "od", "oe", "of", "ö", "o\u0308", "X", "y", "Z", "Z.", "𠮷野家", "吉野家", "!A", "A", "b", "C"]; michael@0: var locales = [undefined, ["de"], ["de-u-co-phonebk"], ["en"], ["ja"], ["sv"]]; michael@0: var options = [ michael@0: undefined, michael@0: {usage: "search"}, michael@0: {sensitivity: "base", ignorePunctuation: true} michael@0: ]; michael@0: michael@0: locales.forEach(function (locales) { michael@0: options.forEach(function (options) { michael@0: var collatorObj = new Intl.Collator(locales, options); michael@0: var compareFunc = collatorObj.compare; michael@0: var referenceSorted = strings.slice(); michael@0: referenceSorted.sort(function (a, b) { return collatorObj.compare(a, b); }); michael@0: var sorted = strings; michael@0: sorted.sort(compareFunc); michael@0: try { michael@0: testArraysAreSame(referenceSorted, sorted); michael@0: } catch (e) { michael@0: e.message += " (Testing with locales " + locales + "; options " + michael@0: (options ? JSON.stringify(options) : options) + ".)"; michael@0: throw e; michael@0: } michael@0: }); michael@0: }); michael@0: