summaryrefslogtreecommitdiff
path: root/test/suite/intl402/ch10/10.1/10.1.1_19_b.js
blob: f1fef270440bbc68bc4227d1a23d86c575df8965 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2012 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/**
 * @description Tests the special handling of the "co" key in Intl.Collator.
 * @author Norbert Lindenberg
 */

function checkCollation(extensionCoValue, usageValue, expectedCollations, expectedUsage) {
    var requestLocale = extensionCoValue !== undefined ? "de-DE-u-co-" + extensionCoValue : "de-DE";
    var options = usageValue !== undefined ? { usage: usageValue } : undefined;
    var collator = new Intl.Collator([requestLocale], options);

    var collation = collator.resolvedOptions().collation;
    if (expectedCollations.indexOf(collation) === -1) {
        $ERROR((extensionCoValue === undefined ? "Default collation" : "Collation for \"" + extensionCoValue) +
            "\" should be " + expectedCollations.join(" or ") + ", but is " + collation + ".");
    }

    var usage = collator.resolvedOptions().usage;
    if (expectedUsage !== usage) {
        $ERROR((usageValue === undefined ? "Default usage" : "Usage") +
            " should be " + expectedUsage + ", but is " + usage + ".");
    }
}

checkCollation(undefined, undefined, ["default"], "sort");

checkCollation("phonebk", undefined, ["phonebk", "default"], "sort");

checkCollation("invalid", undefined, ["default"], "sort");

checkCollation("standard", undefined, ["default"], "sort");

checkCollation("standard", "search", ["default"], "search");

checkCollation("standard", "sort", ["default"], "sort");

checkCollation("search", undefined, ["default"], "sort");

checkCollation("search", "search", ["default"], "search");

checkCollation("search", "sort", ["default"], "sort");