summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/Locale/getters.js
blob: 6454fb1460e2150479d83923a0a7c352ff346224 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright 2018 André Bargull; Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-intl.locale
description: >
    Verifies getters with normal tags.
info: |
    Intl.Locale.prototype.toString ()
    3. Return loc.[[Locale]].

    get Intl.Locale.prototype.baseName
    5. Return the substring of locale corresponding to the
       language ["-" script] ["-" region] *("-" variant)
       subsequence of the langtag grammar.

    get Intl.Locale.prototype.language
    4. Return the substring of locale corresponding to the language production.

    get Intl.Locale.prototype.script
    7. Return the substring of locale corresponding to the script production.

    get Intl.Locale.prototype.region
    7. Return the substring of locale corresponding to the region production.

    get Intl.Locale.prototype.calendar
    3. Return loc.[[Calendar]].

    get Intl.Locale.prototype.collation
    3. Return loc.[[Collation]].

    get Intl.Locale.prototype.hourCycle
    3. Return loc.[[HourCycle]].

    get Intl.Locale.prototype.caseFirst
    This property only exists if %Locale%.[[RelevantExtensionKeys]] contains "kf".
    3. Return loc.[[CaseFirst]].

    get Intl.Locale.prototype.numeric
    This property only exists if %Locale%.[[RelevantExtensionKeys]] contains "kn".
    3. Return loc.[[Numeric]].

    get Intl.Locale.prototype.numberingSystem
    3. Return loc.[[NumberingSystem]].

features: [Intl.Locale]
---*/

// Test all getters return the expected results.
var langtag = "de-latn-de-u-ca-gregory-co-phonebk-hc-h23-kf-true-kn-false-nu-latn";
var loc = new Intl.Locale(langtag);

assert.sameValue(loc.toString(), "de-Latn-DE-u-ca-gregory-co-phonebk-hc-h23-kf-kn-false-nu-latn");
assert.sameValue(loc.baseName, "de-Latn-DE");
assert.sameValue(loc.language, "de");
assert.sameValue(loc.script, "Latn");
assert.sameValue(loc.region, "DE");
assert.sameValue(loc.calendar, "gregory");
assert.sameValue(loc.collation, "phonebk");
assert.sameValue(loc.hourCycle, "h23");
if ("caseFirst" in loc) {
    assert.sameValue(loc.caseFirst, "");
}
if ("numeric" in loc) {
    assert.sameValue(loc.numeric, false);
}
assert.sameValue(loc.numberingSystem, "latn");

// Replace all components through option values and validate the getters still
// return the expected results.
var loc = new Intl.Locale(langtag, {
    language: "ja",
    script: "jpan",
    region: "jp",
    calendar: "japanese",
    collation: "search",
    hourCycle: "h24",
    caseFirst: "false",
    numeric: "true",
    numberingSystem: "jpanfin",
});

assert.sameValue(loc.toString(), "ja-Jpan-JP-u-ca-japanese-co-search-hc-h24-kf-false-kn-nu-jpanfin");
assert.sameValue(loc.baseName, "ja-Jpan-JP");
assert.sameValue(loc.language, "ja");
assert.sameValue(loc.script, "Jpan");
assert.sameValue(loc.region, "JP");
assert.sameValue(loc.calendar, "japanese");
assert.sameValue(loc.collation, "search");
assert.sameValue(loc.hourCycle, "h24");
if ("caseFirst" in loc) {
    assert.sameValue(loc.caseFirst, "false");
}
if ("numeric" in loc) {
    assert.sameValue(loc.numeric, true);
}
assert.sameValue(loc.numberingSystem, "jpanfin");

// Replace only some components through option values and validate the getters
// return the expected results.
var loc = new Intl.Locale(langtag, {
    language: "fr",
    region: "ca",
    collation: "standard",
    hourCycle: "h11",
});

assert.sameValue(loc.toString(), "fr-Latn-CA-u-ca-gregory-co-standard-hc-h11-kf-kn-false-nu-latn");
assert.sameValue(loc.baseName, "fr-Latn-CA");
assert.sameValue(loc.language, "fr");
assert.sameValue(loc.script, "Latn");
assert.sameValue(loc.region, "CA");
assert.sameValue(loc.calendar, "gregory");
assert.sameValue(loc.collation, "standard");
assert.sameValue(loc.hourCycle, "h11");
if ("caseFirst" in loc) {
    assert.sameValue(loc.caseFirst, "");
}
if ("numeric" in loc) {
    assert.sameValue(loc.numeric, false);
}
assert.sameValue(loc.numberingSystem, "latn");

reportCompare(0, 0);