| 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 |
A RangeError is thrown when a language tag includes an invalid transformed extension subtag. |
| 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 |
... |
| 21 |
|
| 22 |
includes: [testIntl.js] |
| 23 |
---*/ |
| 24 |
|
| 25 |
const invalid = [ |
| 26 |
// empty |
| 27 |
"en-t", |
| 28 |
"en-t-a", |
| 29 |
"en-t-x", |
| 30 |
"en-t-0", |
| 31 |
|
| 32 |
// incomplete |
| 33 |
"en-t-", |
| 34 |
"en-t-en-", |
| 35 |
"en-t-0x-", |
| 36 |
|
| 37 |
// tlang: unicode_language_subtag must be 2-3 or 5-8 characters and mustn't |
| 38 |
// contain extlang subtags. |
| 39 |
"en-t-root", |
| 40 |
"en-t-abcdefghi", |
| 41 |
"en-t-ar-aao", |
| 42 |
|
| 43 |
// tlang: unicode_script_subtag must be 4 alphabetical characters, can't |
| 44 |
// be repeated. |
| 45 |
"en-t-en-lat0", |
| 46 |
"en-t-en-latn-latn", |
| 47 |
|
| 48 |
// tlang: unicode_region_subtag must either be 2 alpha characters or a three |
| 49 |
// digit code. |
| 50 |
"en-t-en-0", |
| 51 |
"en-t-en-00", |
| 52 |
"en-t-en-0x", |
| 53 |
"en-t-en-x0", |
| 54 |
"en-t-en-latn-0", |
| 55 |
"en-t-en-latn-00", |
| 56 |
"en-t-en-latn-xyz", |
| 57 |
|
| 58 |
// tlang: unicode_variant_subtag is either 5-8 alphanum characters or 4 |
| 59 |
// characters starting with a digit. |
| 60 |
"en-t-en-abcdefghi", |
| 61 |
"en-t-en-latn-gb-ab", |
| 62 |
"en-t-en-latn-gb-abc", |
| 63 |
"en-t-en-latn-gb-abcd", |
| 64 |
"en-t-en-latn-gb-abcdefghi", |
| 65 |
|
| 66 |
// tkey must be followed by tvalue. |
| 67 |
"en-t-d0", |
| 68 |
"en-t-d0-m0", |
| 69 |
"en-t-d0-x-private", |
| 70 |
]; |
| 71 |
|
| 72 |
for (let tag of invalid) { |
| 73 |
// Make sure the test data is correct. |
| 74 |
assert.sameValue(isCanonicalizedStructurallyValidLanguageTag(tag), false, |
| 75 |
"\"" + tag + "\" isn't a structurally valid language tag."); |
| 76 |
|
| 77 |
assert.throws(RangeError, () => Intl.getCanonicalLocales(tag), `${tag}`); |
| 78 |
} |
| 79 |
|
| 80 |
reportCompare(0, 0); |