getters.js (7541B)
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 3. Return GetLocaleBaseName(_loc_.[[Locale]]). 14 15 GetLocaleBaseName 16 2. Return the longest prefix of _locale_ matched by the 17 <code>unicode_language_id</code> Unicode locale nonterminal. 18 19 get Intl.Locale.prototype.language 20 3. Return GetLocaleLanguage(_loc_.[[Locale]]). 21 22 GetLocaleLanguage 23 1. Let _baseName_ be GetLocaleBaseName(_locale_). 24 2. Assert: The first subtag of _baseName_ can be matched by the 25 <code>unicode_language_subtag</code> Unicode locale nonterminal. 26 3. Return the first subtag of _baseName_. 27 28 get Intl.Locale.prototype.script 29 3. Return GetLocaleScript(_loc_.[[Locale]]). 30 31 GetLocaleScript 32 1. Let _baseName_ be GetLocaleBaseName(_locale_). 33 2. Assert: _baseName_ contains at most one subtag that can be matched by the 34 <code>unicode_script_subtag</code> Unicode locale nonterminal. 35 3. If _baseName_ contains a subtag matched by the 36 <code>unicode_script_subtag</code> Unicode locale nonterminal, return 37 that subtag. 38 4. Return *undefined*. 39 40 get Intl.Locale.prototype.region 41 3. Return GetLocaleRegion(_loc_.[[Locale]]). 42 43 GetLocaleRegion 44 1. Let _baseName_ be GetLocaleBaseName(_locale_). 45 2. NOTE: A <code>unicode_region_subtag</code> subtag is only valid 46 immediately after an initial <code>unicode_language_subtag</code> subtag, 47 optionally with a single <code>unicode_script_subtag</code> subtag 48 between them. In that position, <code>unicode_region_subtag</code> cannot 49 be confused with any other valid subtag because all their productions are 50 disjoint. 51 3. Assert: The first subtag of _baseName_ can be matched by the 52 <code>unicode_language_subtag</code> Unicode locale nonterminal. 53 4. Let _baseNameTail_ be the suffix of _baseName_ following the first 54 subtag. 55 5. Assert: _baseNameTail_ contains at most one subtag that can be matched by 56 the <code>unicode_region_subtag</code> Unicode locale nonterminal. 57 6. If _baseNameTail_ contains a subtag matched by the 58 <code>unicode_region_subtag</code> Unicode locale nonterminal, return 59 that subtag. 60 7. Return *undefined*. 61 62 get Intl.Locale.prototype.variants 63 3. Return GetLocaleVariants(_loc_.[[Locale]]). 64 65 GetLocaleVariants 66 1. Let _baseName_ be GetLocaleBaseName(_locale_). 67 2. NOTE: Each subtag in _baseName_ that is preceded by *"-"* is either a 68 <code>unicode_script_subtag</code>, <code>unicode_region_subtag</code>, 69 or <code>unicode_variant_subtag</code>, but any substring matched by 70 <code>unicode_variant_subtag</code> is strictly longer than any prefix 71 thereof which could also be matched by one of the other productions. 72 3. Let _variants_ be the longest suffix of _baseName_ that starts with a 73 *"-"* followed by a <emu-not-ref>substring</emu-not-ref> that is matched 74 by the <code>unicode_variant_subtag</code> Unicode locale nonterminal. If 75 there is no such suffix, return *undefined*. 76 4. Return the substring of _variants_ from 1. 77 78 get Intl.Locale.prototype.calendar 79 3. Return loc.[[Calendar]]. 80 81 get Intl.Locale.prototype.collation 82 3. Return loc.[[Collation]]. 83 84 get Intl.Locale.prototype.hourCycle 85 3. Return loc.[[HourCycle]]. 86 87 get Intl.Locale.prototype.caseFirst 88 This property only exists if %Locale%.[[RelevantExtensionKeys]] contains "kf". 89 3. Return loc.[[CaseFirst]]. 90 91 get Intl.Locale.prototype.numeric 92 This property only exists if %Locale%.[[RelevantExtensionKeys]] contains "kn". 93 3. Return loc.[[Numeric]]. 94 95 get Intl.Locale.prototype.numberingSystem 96 3. Return loc.[[NumberingSystem]]. 97 98 features: [Intl.Locale] 99 ---*/ 100 101 // Test all getters return the expected results. 102 var langtag = "de-latn-de-fonipa-1996-u-ca-gregory-co-phonebk-hc-h23-kf-true-kn-false-nu-latn"; 103 var loc = new Intl.Locale(langtag); 104 105 assert.sameValue(loc.toString(), "de-Latn-DE-1996-fonipa-u-ca-gregory-co-phonebk-hc-h23-kf-kn-false-nu-latn"); 106 assert.sameValue(loc.baseName, "de-Latn-DE-1996-fonipa"); 107 assert.sameValue(loc.language, "de"); 108 assert.sameValue(loc.script, "Latn"); 109 assert.sameValue(loc.region, "DE"); 110 assert.sameValue(loc.variants, "1996-fonipa"); 111 assert.sameValue(loc.calendar, "gregory"); 112 assert.sameValue(loc.collation, "phonebk"); 113 assert.sameValue(loc.hourCycle, "h23"); 114 if ("caseFirst" in loc) { 115 assert.sameValue(loc.caseFirst, ""); 116 } 117 if ("numeric" in loc) { 118 assert.sameValue(loc.numeric, false); 119 } 120 assert.sameValue(loc.numberingSystem, "latn"); 121 122 // Replace all components through option values and validate the getters still 123 // return the expected results. 124 var loc = new Intl.Locale(langtag, { 125 language: "ja", 126 script: "jpan", 127 region: "jp", 128 variants: "Hepburn", 129 calendar: "japanese", 130 collation: "search", 131 hourCycle: "h24", 132 caseFirst: "false", 133 numeric: "true", 134 numberingSystem: "jpanfin", 135 }); 136 137 assert.sameValue(loc.toString(), "ja-Jpan-JP-hepburn-u-ca-japanese-co-search-hc-h24-kf-false-kn-nu-jpanfin"); 138 assert.sameValue(loc.baseName, "ja-Jpan-JP-hepburn"); 139 assert.sameValue(loc.language, "ja"); 140 assert.sameValue(loc.script, "Jpan"); 141 assert.sameValue(loc.region, "JP"); 142 assert.sameValue(loc.variants, "hepburn"); 143 assert.sameValue(loc.calendar, "japanese"); 144 assert.sameValue(loc.collation, "search"); 145 assert.sameValue(loc.hourCycle, "h24"); 146 if ("caseFirst" in loc) { 147 assert.sameValue(loc.caseFirst, "false"); 148 } 149 if ("numeric" in loc) { 150 assert.sameValue(loc.numeric, true); 151 } 152 assert.sameValue(loc.numberingSystem, "jpanfin"); 153 154 // Replace only some components through option values and validate the getters 155 // return the expected results. 156 var loc = new Intl.Locale(langtag, { 157 language: "fr", 158 region: "ca", 159 collation: "standard", 160 hourCycle: "h11", 161 }); 162 163 assert.sameValue(loc.toString(), "fr-Latn-CA-1996-fonipa-u-ca-gregory-co-standard-hc-h11-kf-kn-false-nu-latn"); 164 assert.sameValue(loc.baseName, "fr-Latn-CA-1996-fonipa"); 165 assert.sameValue(loc.language, "fr"); 166 assert.sameValue(loc.script, "Latn"); 167 assert.sameValue(loc.region, "CA"); 168 assert.sameValue(loc.variants, "1996-fonipa"); 169 assert.sameValue(loc.calendar, "gregory"); 170 assert.sameValue(loc.collation, "standard"); 171 assert.sameValue(loc.hourCycle, "h11"); 172 if ("caseFirst" in loc) { 173 assert.sameValue(loc.caseFirst, ""); 174 } 175 if ("numeric" in loc) { 176 assert.sameValue(loc.numeric, false); 177 } 178 assert.sameValue(loc.numberingSystem, "latn"); 179 180 // Check that "und" language subtag returns "und" for `language` getter 181 var loc = new Intl.Locale("und"); 182 183 assert.sameValue(loc.toString(), "und"); 184 assert.sameValue(loc.baseName, "und"); 185 assert.sameValue(loc.language, "und"); 186 assert.sameValue(loc.script, undefined); 187 assert.sameValue(loc.region, undefined); 188 assert.sameValue(loc.variants, undefined); 189 190 var loc = new Intl.Locale("und-US-u-co-emoji"); 191 192 assert.sameValue(loc.toString(), "und-US-u-co-emoji"); 193 assert.sameValue(loc.baseName, "und-US"); 194 assert.sameValue(loc.language, "und"); 195 assert.sameValue(loc.script, undefined); 196 assert.sameValue(loc.region, "US"); 197 assert.sameValue(loc.variants, undefined); 198 if ("collation" in loc) { 199 assert.sameValue(loc.collation, "emoji"); 200 } 201 202 reportCompare(0, 0);