| 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 "ca" 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="ca" [...] alias="calendar"> |
| 31 |
const testData = { |
| 32 |
// <type name="ethioaa" [...] alias="ethiopic-amete-alem"/> |
| 33 |
"ethiopic-amete-alem": "ethioaa", |
| 34 |
|
| 35 |
// <type name="islamic-civil" [...] /> |
| 36 |
// <type name="islamicc" [...] deprecated="true" preferred="islamic-civil" alias="islamic-civil"/> |
| 37 |
// |
| 38 |
// "name" and "alias" for "islamic-civil" don't quite match of what's spec'ed in UTS 35, §3.2.1. |
| 39 |
// Specifically following §3.2.1 to the letter means "islamicc" is the canonical value whereas |
| 40 |
// "islamic-civil" is an alias value. Assume the definitions in |
| 41 |
// https://unicode.org/reports/tr35/#Unicode_Locale_Extension_Data_Files overrule UTS 35, §3.2.1. |
| 42 |
"islamicc": "islamic-civil", |
| 43 |
}; |
| 44 |
|
| 45 |
for (let [alias, name] of Object.entries(testData)) { |
| 46 |
let tag = "und-u-ca-" + alias; |
| 47 |
let canonical = "und-u-ca-" + name; |
| 48 |
|
| 49 |
// Make sure the test data is correct. |
| 50 |
assert.sameValue(isCanonicalizedStructurallyValidLanguageTag(tag), false, |
| 51 |
"\"" + tag + "\" isn't a canonical language tag."); |
| 52 |
assert(isCanonicalizedStructurallyValidLanguageTag(canonical), |
| 53 |
"\"" + canonical + "\" is a canonical and structurally valid language tag."); |
| 54 |
|
| 55 |
let result = Intl.getCanonicalLocales(tag); |
| 56 |
assert.sameValue(result.length, 1); |
| 57 |
assert.sameValue(result[0], canonical); |
| 58 |
} |
| 59 |
|
| 60 |
reportCompare(0, 0); |