|
1 // Copyright 2012 Mozilla Corporation. All rights reserved. |
|
2 // This code is governed by the BSD license found in the LICENSE file. |
|
3 |
|
4 /** |
|
5 * @description Tests the special handling of the "co" key in Intl.Collator. |
|
6 * @author Norbert Lindenberg |
|
7 */ |
|
8 |
|
9 function checkCollation(extensionCoValue, usageValue, expectedCollations, expectedUsage) { |
|
10 var requestLocale = extensionCoValue !== undefined ? "de-DE-u-co-" + extensionCoValue : "de-DE"; |
|
11 var options = usageValue !== undefined ? { usage: usageValue } : undefined; |
|
12 var collator = new Intl.Collator([requestLocale], options); |
|
13 |
|
14 var collation = collator.resolvedOptions().collation; |
|
15 if (expectedCollations.indexOf(collation) === -1) { |
|
16 $ERROR((extensionCoValue === undefined ? "Default collation" : "Collation for \"" + extensionCoValue) + |
|
17 "\" should be " + expectedCollations.join(" or ") + ", but is " + collation + "."); |
|
18 } |
|
19 |
|
20 var usage = collator.resolvedOptions().usage; |
|
21 if (expectedUsage !== usage) { |
|
22 $ERROR((usageValue === undefined ? "Default usage" : "Usage") + |
|
23 " should be " + expectedUsage + ", but is " + usage + "."); |
|
24 } |
|
25 } |
|
26 |
|
27 checkCollation(undefined, undefined, ["default"], "sort"); |
|
28 |
|
29 checkCollation("phonebk", undefined, ["phonebk", "default"], "sort"); |
|
30 |
|
31 checkCollation("invalid", undefined, ["default"], "sort"); |
|
32 |
|
33 checkCollation("standard", undefined, ["default"], "sort"); |
|
34 |
|
35 checkCollation("standard", "search", ["default"], "search"); |
|
36 |
|
37 checkCollation("standard", "sort", ["default"], "sort"); |
|
38 |
|
39 checkCollation("search", undefined, ["default"], "sort"); |
|
40 |
|
41 checkCollation("search", "search", ["default"], "search"); |
|
42 |
|
43 checkCollation("search", "sort", ["default"], "sort"); |
|
44 |