| 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 "ms" 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="ms" [...] alias="measure" since="28"> |
| 31 |
const testData = { |
| 32 |
// <type name="uksystem" [...] alias="imperial" since="28" /> |
| 33 |
"imperial": "uksystem", |
| 34 |
}; |
| 35 |
|
| 36 |
for (let [alias, name] of Object.entries(testData)) { |
| 37 |
let tag = "und-u-ms-" + alias; |
| 38 |
let canonical = "und-u-ms-" + name; |
| 39 |
|
| 40 |
// Make sure the test data is correct. |
| 41 |
assert.sameValue(isCanonicalizedStructurallyValidLanguageTag(tag), false, |
| 42 |
"\"" + tag + "\" isn't a canonical language tag."); |
| 43 |
assert(isCanonicalizedStructurallyValidLanguageTag(canonical), |
| 44 |
"\"" + canonical + "\" is a canonical and structurally valid language tag."); |
| 45 |
|
| 46 |
let result = Intl.getCanonicalLocales(tag); |
| 47 |
assert.sameValue(result.length, 1); |
| 48 |
assert.sameValue(result[0], canonical); |
| 49 |
} |
| 50 |
|
| 51 |
reportCompare(0, 0); |