summaryrefslogtreecommitdiffstats
path: root/intl/locale/tests/unit/test_collation_mac_icu.js
blob: 32ebc60ebccae34dc5e4c1438bd19a55d6276b74 (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
var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;

Cu.import("resource://gre/modules/Services.jsm");

function run_test()
{
  var input = [
    "Argentina",
    "Oerlikon",
    "Offenbach",
    "Sverige",
    "Vaticano",
    "Zimbabwe",
    "la France",
    "¡viva España!",
    "Österreich",
    "中国",
    "日本",
    "한국",
  ];

  function test(locale, expected) {
    var localeSvc = Cc["@mozilla.org/intl/nslocaleservice;1"].
      getService(Ci.nsILocaleService);
    var collator = Cc["@mozilla.org/intl/collation-factory;1"].
      createInstance(Ci.nsICollationFactory).
      CreateCollation(localeSvc.newLocale(locale));
    var strength = Ci.nsICollation.kCollationStrengthDefault;
    var actual = input.sort((x, y) => collator.compareString(strength, x,y));
    deepEqual(actual, expected, locale);
  }

  // Locale en-US; default options.
  test("en-US", [
    "¡viva España!",
    "Argentina",
    "la France",
    "Oerlikon",
    "Offenbach",
    "Österreich",
    "Sverige",
    "Vaticano",
    "Zimbabwe",
    "한국",
    "中国",
    "日本",
  ]);

  // Locale sv-SE; default options.
  // Swedish treats "Ö" as a separate character, which sorts after "Z".
  test("sv-SE", [
    "¡viva España!",
    "Argentina",
    "la France",
    "Oerlikon",
    "Offenbach",
    "Sverige",
    "Vaticano",
    "Zimbabwe",
    "Österreich",
    "한국",
    "中国",
    "日本",
  ]);

  // Locale de-DE; default options.
  // In German standard sorting, umlauted characters are treated as variants
  // of their base characters: ä ≅ a, ö ≅ o, ü ≅ u.
  test("de-DE", [
    "¡viva España!",
    "Argentina",
    "la France",
    "Oerlikon",
    "Offenbach",
    "Österreich",
    "Sverige",
    "Vaticano",
    "Zimbabwe",
    "한국",
    "中国",
    "日本",
  ]);
}