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 the special handling of the "co" key in Intl.Collator. michael@0: * @author Norbert Lindenberg michael@0: */ michael@0: michael@0: function checkCollation(extensionCoValue, usageValue, expectedCollations, expectedUsage) { michael@0: var requestLocale = extensionCoValue !== undefined ? "de-DE-u-co-" + extensionCoValue : "de-DE"; michael@0: var options = usageValue !== undefined ? { usage: usageValue } : undefined; michael@0: var collator = new Intl.Collator([requestLocale], options); michael@0: michael@0: var collation = collator.resolvedOptions().collation; michael@0: if (expectedCollations.indexOf(collation) === -1) { michael@0: $ERROR((extensionCoValue === undefined ? "Default collation" : "Collation for \"" + extensionCoValue) + michael@0: "\" should be " + expectedCollations.join(" or ") + ", but is " + collation + "."); michael@0: } michael@0: michael@0: var usage = collator.resolvedOptions().usage; michael@0: if (expectedUsage !== usage) { michael@0: $ERROR((usageValue === undefined ? "Default usage" : "Usage") + michael@0: " should be " + expectedUsage + ", but is " + usage + "."); michael@0: } michael@0: } michael@0: michael@0: checkCollation(undefined, undefined, ["default"], "sort"); michael@0: michael@0: checkCollation("phonebk", undefined, ["phonebk", "default"], "sort"); michael@0: michael@0: checkCollation("invalid", undefined, ["default"], "sort"); michael@0: michael@0: checkCollation("standard", undefined, ["default"], "sort"); michael@0: michael@0: checkCollation("standard", "search", ["default"], "search"); michael@0: michael@0: checkCollation("standard", "sort", ["default"], "sort"); michael@0: michael@0: checkCollation("search", undefined, ["default"], "sort"); michael@0: michael@0: checkCollation("search", "search", ["default"], "search"); michael@0: michael@0: checkCollation("search", "sort", ["default"], "sort"); michael@0: