| 1 |
// Copyright 2018 André Bargull; Igalia, S.L. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
esid: sec-intl.locale |
| 6 |
description: > |
| 7 |
Verifies getters with normal tags. |
| 8 |
info: | |
| 9 |
Intl.Locale.prototype.toString () |
| 10 |
3. Return loc.[[Locale]]. |
| 11 |
|
| 12 |
get Intl.Locale.prototype.baseName |
| 13 |
5. Return the substring of locale corresponding to the |
| 14 |
language ["-" script] ["-" region] *("-" variant) |
| 15 |
subsequence of the langtag grammar. |
| 16 |
|
| 17 |
get Intl.Locale.prototype.language |
| 18 |
4. Return the substring of locale corresponding to the language production. |
| 19 |
|
| 20 |
get Intl.Locale.prototype.script |
| 21 |
7. Return the substring of locale corresponding to the script production. |
| 22 |
|
| 23 |
get Intl.Locale.prototype.region |
| 24 |
7. Return the substring of locale corresponding to the region production. |
| 25 |
|
| 26 |
get Intl.Locale.prototype.calendar |
| 27 |
3. Return loc.[[Calendar]]. |
| 28 |
|
| 29 |
get Intl.Locale.prototype.collation |
| 30 |
3. Return loc.[[Collation]]. |
| 31 |
|
| 32 |
get Intl.Locale.prototype.hourCycle |
| 33 |
3. Return loc.[[HourCycle]]. |
| 34 |
|
| 35 |
get Intl.Locale.prototype.caseFirst |
| 36 |
This property only exists if %Locale%.[[RelevantExtensionKeys]] contains "kf". |
| 37 |
3. Return loc.[[CaseFirst]]. |
| 38 |
|
| 39 |
get Intl.Locale.prototype.numeric |
| 40 |
This property only exists if %Locale%.[[RelevantExtensionKeys]] contains "kn". |
| 41 |
3. Return loc.[[Numeric]]. |
| 42 |
|
| 43 |
get Intl.Locale.prototype.numberingSystem |
| 44 |
3. Return loc.[[NumberingSystem]]. |
| 45 |
|
| 46 |
features: [Intl.Locale] |
| 47 |
---*/ |
| 48 |
|
| 49 |
// Test all getters return the expected results. |
| 50 |
var langtag = "de-latn-de-u-ca-gregory-co-phonebk-hc-h23-kf-true-kn-false-nu-latn"; |
| 51 |
var loc = new Intl.Locale(langtag); |
| 52 |
|
| 53 |
assert.sameValue(loc.toString(), "de-Latn-DE-u-ca-gregory-co-phonebk-hc-h23-kf-kn-false-nu-latn"); |
| 54 |
assert.sameValue(loc.baseName, "de-Latn-DE"); |
| 55 |
assert.sameValue(loc.language, "de"); |
| 56 |
assert.sameValue(loc.script, "Latn"); |
| 57 |
assert.sameValue(loc.region, "DE"); |
| 58 |
assert.sameValue(loc.calendar, "gregory"); |
| 59 |
assert.sameValue(loc.collation, "phonebk"); |
| 60 |
assert.sameValue(loc.hourCycle, "h23"); |
| 61 |
if ("caseFirst" in loc) { |
| 62 |
assert.sameValue(loc.caseFirst, ""); |
| 63 |
} |
| 64 |
if ("numeric" in loc) { |
| 65 |
assert.sameValue(loc.numeric, false); |
| 66 |
} |
| 67 |
assert.sameValue(loc.numberingSystem, "latn"); |
| 68 |
|
| 69 |
// Replace all components through option values and validate the getters still |
| 70 |
// return the expected results. |
| 71 |
var loc = new Intl.Locale(langtag, { |
| 72 |
language: "ja", |
| 73 |
script: "jpan", |
| 74 |
region: "jp", |
| 75 |
calendar: "japanese", |
| 76 |
collation: "search", |
| 77 |
hourCycle: "h24", |
| 78 |
caseFirst: "false", |
| 79 |
numeric: "true", |
| 80 |
numberingSystem: "jpanfin", |
| 81 |
}); |
| 82 |
|
| 83 |
assert.sameValue(loc.toString(), "ja-Jpan-JP-u-ca-japanese-co-search-hc-h24-kf-false-kn-nu-jpanfin"); |
| 84 |
assert.sameValue(loc.baseName, "ja-Jpan-JP"); |
| 85 |
assert.sameValue(loc.language, "ja"); |
| 86 |
assert.sameValue(loc.script, "Jpan"); |
| 87 |
assert.sameValue(loc.region, "JP"); |
| 88 |
assert.sameValue(loc.calendar, "japanese"); |
| 89 |
assert.sameValue(loc.collation, "search"); |
| 90 |
assert.sameValue(loc.hourCycle, "h24"); |
| 91 |
if ("caseFirst" in loc) { |
| 92 |
assert.sameValue(loc.caseFirst, "false"); |
| 93 |
} |
| 94 |
if ("numeric" in loc) { |
| 95 |
assert.sameValue(loc.numeric, true); |
| 96 |
} |
| 97 |
assert.sameValue(loc.numberingSystem, "jpanfin"); |
| 98 |
|
| 99 |
// Replace only some components through option values and validate the getters |
| 100 |
// return the expected results. |
| 101 |
var loc = new Intl.Locale(langtag, { |
| 102 |
language: "fr", |
| 103 |
region: "ca", |
| 104 |
collation: "standard", |
| 105 |
hourCycle: "h11", |
| 106 |
}); |
| 107 |
|
| 108 |
assert.sameValue(loc.toString(), "fr-Latn-CA-u-ca-gregory-co-standard-hc-h11-kf-kn-false-nu-latn"); |
| 109 |
assert.sameValue(loc.baseName, "fr-Latn-CA"); |
| 110 |
assert.sameValue(loc.language, "fr"); |
| 111 |
assert.sameValue(loc.script, "Latn"); |
| 112 |
assert.sameValue(loc.region, "CA"); |
| 113 |
assert.sameValue(loc.calendar, "gregory"); |
| 114 |
assert.sameValue(loc.collation, "standard"); |
| 115 |
assert.sameValue(loc.hourCycle, "h11"); |
| 116 |
if ("caseFirst" in loc) { |
| 117 |
assert.sameValue(loc.caseFirst, ""); |
| 118 |
} |
| 119 |
if ("numeric" in loc) { |
| 120 |
assert.sameValue(loc.numeric, false); |
| 121 |
} |
| 122 |
assert.sameValue(loc.numberingSystem, "latn"); |
| 123 |
|
| 124 |
// Check that "und" language subtag returns "und" for `language` getter |
| 125 |
var loc = new Intl.Locale("und"); |
| 126 |
|
| 127 |
assert.sameValue(loc.toString(), "und"); |
| 128 |
assert.sameValue(loc.baseName, "und"); |
| 129 |
assert.sameValue(loc.language, "und"); |
| 130 |
assert.sameValue(loc.script, undefined); |
| 131 |
assert.sameValue(loc.region, undefined); |
| 132 |
|
| 133 |
var loc = new Intl.Locale("und-US-u-co-emoji"); |
| 134 |
|
| 135 |
assert.sameValue(loc.toString(), "und-US-u-co-emoji"); |
| 136 |
assert.sameValue(loc.baseName, "und-US"); |
| 137 |
assert.sameValue(loc.language, "und"); |
| 138 |
assert.sameValue(loc.script, undefined); |
| 139 |
assert.sameValue(loc.region, "US"); |
| 140 |
if ("collation" in loc) { |
| 141 |
assert.sameValue(loc.collation, "emoji"); |
| 142 |
} |
| 143 |
|
| 144 |
reportCompare(0, 0); |