| 1 |
// Copyright (C) 2020 André Bargull. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
esid: sec-intl.getcanonicallocales |
| 6 |
description: > |
| 7 |
Test Unicode extension subtag canonicalisation for the "tz" extension key. |
| 8 |
info: | |
| 9 |
8.2.1 Intl.getCanonicalLocales (locales) |
| 10 |
1. Let ll be ? CanonicalizeLocaleList(locales). |
| 11 |
2. Return CreateArrayFromList(ll). |
| 12 |
|
| 13 |
9.2.1 CanonicalizeLocaleList (locales) |
| 14 |
... |
| 15 |
7. Repeat, while k < len |
| 16 |
... |
| 17 |
c. If kPresent is true, then |
| 18 |
... |
| 19 |
v. If IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception. |
| 20 |
vi. Let canonicalizedTag be CanonicalizeUnicodeLocaleId(tag). |
| 21 |
... |
| 22 |
|
| 23 |
UTS 35, §3.2.1 Canonical Unicode Locale Identifiers |
| 24 |
Use the bcp47 data to replace keys, types, tfields, and tvalues by their canonical forms. |
| 25 |
See Section 3.6.4 U Extension Data Files) and Section 3.7.1 T Extension Data Files. The |
| 26 |
aliases are in the alias attribute value, while the canonical is in the name attribute value. |
| 27 |
includes: [testIntl.js] |
| 28 |
---*/ |
| 29 |
|
| 30 |
// <key name="tz" [...] alias="timezone"> |
| 31 |
const testData = { |
| 32 |
// Similar to the "ca" extension key, assume "preferred" holds the canonical |
| 33 |
// value and "name" the alias value. |
| 34 |
|
| 35 |
// <type name="cnckg" [...] deprecated="true" preferred="cnsha"/> |
| 36 |
"cnckg": "cnsha", |
| 37 |
|
| 38 |
// NB: "Eire" matches the |uvalue| production. |
| 39 |
// <type name="iedub" [...] alias="Europe/Dublin Eire"/> |
| 40 |
"eire": "iedub", |
| 41 |
|
| 42 |
// NB: "EST" matches the |uvalue| production. |
| 43 |
// <type name="papty" [...] alias="America/Panama EST"/> |
| 44 |
"est": "papty", |
| 45 |
|
| 46 |
// NB: "GMT0" matches the |uvalue| production. |
| 47 |
// <type name="gmt" [...] alias="Etc/GMT Etc/GMT+0 Etc/GMT-0 Etc/GMT0 Etc/Greenwich GMT GMT+0 GMT-0 GMT0 Greenwich"/> |
| 48 |
"gmt0": "gmt", |
| 49 |
|
| 50 |
// NB: "UCT" matches the |uvalue| production. |
| 51 |
// <type name="utc" [...] alias="Etc/UTC Etc/UCT Etc/Universal Etc/Zulu UCT UTC Universal Zulu"/> |
| 52 |
"uct": "utc", |
| 53 |
|
| 54 |
// NB: "Zulu" matches the |uvalue| production. |
| 55 |
// <type name="utc" [...] alias="Etc/UTC Etc/UCT Etc/Universal Etc/Zulu UCT UTC Universal Zulu"/> |
| 56 |
"zulu": "utc", |
| 57 |
}; |
| 58 |
|
| 59 |
for (let [alias, name] of Object.entries(testData)) { |
| 60 |
let tag = "und-u-tz-" + alias; |
| 61 |
let canonical = "und-u-tz-" + name; |
| 62 |
|
| 63 |
// Make sure the test data is correct. |
| 64 |
assert.sameValue(isCanonicalizedStructurallyValidLanguageTag(tag), false, |
| 65 |
"\"" + tag + "\" isn't a canonical language tag."); |
| 66 |
assert(isCanonicalizedStructurallyValidLanguageTag(canonical), |
| 67 |
"\"" + canonical + "\" is a canonical and structurally valid language tag."); |
| 68 |
|
| 69 |
let result = Intl.getCanonicalLocales(tag); |
| 70 |
assert.sameValue(result.length, 1); |
| 71 |
assert.sameValue(result[0], canonical); |
| 72 |
} |
| 73 |
|
| 74 |
reportCompare(0, 0); |