summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/Collator/collation.js
blob: f73728b8766cb26e66b453fca8e3319faa4df886 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// |reftest| skip-if(!this.hasOwnProperty("Intl"))

// Collation can be set as Unicode locale extension or as a property.
{
  let c1 = new Intl.Collator("de", {usage: "sort"});
  let c2 = new Intl.Collator("de", {usage: "sort", collation: "phonebk"});
  let c3 = new Intl.Collator("de-u-co-phonebk", {usage: "sort"});

  assertEq(c1.resolvedOptions().locale, "de");
  assertEq(c2.resolvedOptions().locale, "de");
  assertEq(c3.resolvedOptions().locale, "de-u-co-phonebk");

  assertEq(c1.resolvedOptions().collation, "default");
  assertEq(c2.resolvedOptions().collation, "phonebk");
  assertEq(c3.resolvedOptions().collation, "phonebk");

  assertEq(c1.compare("ä", "ae"), -1);
  assertEq(c2.compare("ä", "ae"), 1);
  assertEq(c3.compare("ä", "ae"), 1);
}

// Collation property overrides any Unicode locale extension.
{
  let c1 = new Intl.Collator("de-u-co-eor", {usage: "sort"});
  let c2 = new Intl.Collator("de-u-co-eor", {usage: "sort", collation: "phonebk"});

  // Ensure "eor" collation is supported.
  assertEq(c1.resolvedOptions().locale, "de-u-co-eor");
  assertEq(c1.resolvedOptions().collation, "eor");

  // "phonebk" property overrides the Unicode locale extension.
  assertEq(c2.resolvedOptions().locale, "de");
  assertEq(c2.resolvedOptions().collation, "phonebk");

  assertEq(c1.compare("ä", "ae"), -1);
  assertEq(c2.compare("ä", "ae"), 1);
}

// The default sort collation can't be requested.
{
  // The default sort collation for Swedish (sv) was "reformed" before CLDR 42.
  // It wasn't possible to override this and select the default root sort
  // collation. Use English (en) as a locale which uses the root sort collation
  // for comparison.
  let c1 = new Intl.Collator("sv", {usage: "sort"});
  let c2 = new Intl.Collator("sv-u-co-reformed", {usage: "sort"});
  let c3 = new Intl.Collator("sv-u-co-standard", {usage: "sort"});
  let c4 = new Intl.Collator("sv-u-co-default", {usage: "sort"});
  let c5 = new Intl.Collator("en", {usage: "sort"});

  assertEq(c1.resolvedOptions().locale, "sv");
  assertEq(c2.resolvedOptions().locale, "sv");
  assertEq(c3.resolvedOptions().locale, "sv");
  assertEq(c4.resolvedOptions().locale, "sv");
  assertEq(c5.resolvedOptions().locale, "en");

  assertEq(c1.resolvedOptions().collation, "default");
  assertEq(c2.resolvedOptions().collation, "default");
  assertEq(c3.resolvedOptions().collation, "default");
  assertEq(c4.resolvedOptions().collation, "default");
  assertEq(c5.resolvedOptions().collation, "default");

  assertEq(c1.compare("y", "ü"), -1);
  assertEq(c2.compare("y", "ü"), -1);
  assertEq(c3.compare("y", "ü"), -1);
  assertEq(c4.compare("y", "ü"), -1);
  assertEq(c5.compare("y", "ü"), 1);
}

// Search collations ignore any collation overrides.
{
  let c1 = new Intl.Collator("de", {usage: "search"});
  let c2 = new Intl.Collator("de", {usage: "search", collation: "phonebk"});
  let c3 = new Intl.Collator("de-u-co-phonebk", {usage: "search"});

  assertEq(c1.resolvedOptions().locale, "de");
  assertEq(c2.resolvedOptions().locale, "de");
  assertEq(c3.resolvedOptions().locale, "de");

  assertEq(c1.resolvedOptions().collation, "default");
  assertEq(c2.resolvedOptions().collation, "default");
  assertEq(c3.resolvedOptions().collation, "default");

  assertEq(c1.compare("ä", "ae"), 1);
  assertEq(c2.compare("ä", "ae"), 1);
  assertEq(c3.compare("ä", "ae"), 1);
}

if (typeof reportCompare === "function")
  reportCompare(0, 0, "ok");