| 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 |
"kb", "kc", "kh", "kk", and "kn" Unicode extension keys canonicalise "yes" to "true". |
| 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 |
|
| 28 |
UTS 35, §3.2.1 Canonical Unicode Locale Identifiers |
| 29 |
Any type or tfield value "true" is removed. |
| 30 |
includes: [testIntl.js] |
| 31 |
---*/ |
| 32 |
|
| 33 |
const unicodeKeys = [ |
| 34 |
// <key name="kb" [...] alias="colBackwards"> |
| 35 |
// <type name="true" [...] alias="yes"/> |
| 36 |
"kb", |
| 37 |
|
| 38 |
// <key name="kc" [...] alias="colCaseLevel"> |
| 39 |
// <type name="true" [...] alias="yes"/> |
| 40 |
"kc", |
| 41 |
|
| 42 |
// <key name="kh" [...] alias="colBackwards"> |
| 43 |
// <type name="true" [...] alias="yes"/> |
| 44 |
"kh", |
| 45 |
|
| 46 |
// <key name="kh" [...] alias="colHiraganaQuaternary"> |
| 47 |
// <type name="true" [...] alias="yes"/> |
| 48 |
"kk", |
| 49 |
|
| 50 |
// <key name="kn" [...] alias="colNumeric"> |
| 51 |
// <type name="true" [...] alias="yes"/> |
| 52 |
"kn", |
| 53 |
]; |
| 54 |
|
| 55 |
for (let key of unicodeKeys) { |
| 56 |
let tag = `und-u-${key}-yes`; |
| 57 |
let canonical = `und-u-${key}`; |
| 58 |
|
| 59 |
// Make sure the test data is correct. |
| 60 |
assert.sameValue(isCanonicalizedStructurallyValidLanguageTag(tag), false, |
| 61 |
"\"" + tag + "\" isn't a canonical language tag."); |
| 62 |
assert(isCanonicalizedStructurallyValidLanguageTag(canonical), |
| 63 |
"\"" + canonical + "\" is a canonical and structurally valid language tag."); |
| 64 |
|
| 65 |
let result = Intl.getCanonicalLocales(tag); |
| 66 |
assert.sameValue(result.length, 1); |
| 67 |
assert.sameValue(result[0], canonical); |
| 68 |
} |
| 69 |
|
| 70 |
// Test some other Unicode extension keys which don't contain an alias entry to |
| 71 |
// canonicalise "yes" to "true". |
| 72 |
const otherUnicodeKeys = [ |
| 73 |
"ka", "kf", "kr", "ks", "kv", |
| 74 |
]; |
| 75 |
|
| 76 |
for (let key of otherUnicodeKeys) { |
| 77 |
let tag = `und-u-${key}-yes`; |
| 78 |
|
| 79 |
// Make sure the test data is correct. |
| 80 |
assert(isCanonicalizedStructurallyValidLanguageTag(tag), |
| 81 |
"\"" + tag + "\" is a canonical and structurally valid language tag."); |
| 82 |
|
| 83 |
let result = Intl.getCanonicalLocales(tag); |
| 84 |
assert.sameValue(result.length, 1); |
| 85 |
assert.sameValue(result[0], tag); |
| 86 |
} |
| 87 |
|
| 88 |
reportCompare(0, 0); |