Debian Codegraph @

js/src/tests/test262/intl402/Intl/getCanonicalLocales/transformed-ext-canonical.js

raw
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 canonicalisation within transformed extension subtags.
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 includes: [testIntl.js]
24 ---*/
25
26 const testData = {
27 // Variant subtags are alphabetically ordered.
28 "sl-t-sl-rozaj-biske-1994": "sl-t-sl-1994-biske-rozaj",
29
30 // tfield subtags are alphabetically ordered.
31 // (Also tests subtag case normalisation.)
32 "DE-T-M0-DIN-K0-QWERTZ": "de-t-k0-qwertz-m0-din",
33
34 // "true" tvalue subtags aren't removed.
35 // (UTS 35 version 36, §3.2.1 claims otherwise, but tkey must be followed by
36 // tvalue, so that's likely a spec bug in UTS 35.)
37 "en-t-m0-true": "en-t-m0-true",
38
39 // tlang subtags are canonicalised.
40 "en-t-iw": "en-t-he",
41
42 // Deprecated tvalue subtags are replaced by their preferred value.
43 "und-Latn-t-und-hani-m0-names": "und-Latn-t-und-hani-m0-prprname",
44 };
45
46 for (let [tag, canonical] of Object.entries(testData)) {
47 // Make sure the test data is correct.
48 assert(isCanonicalizedStructurallyValidLanguageTag(canonical),
49 "\"" + canonical + "\" is a canonical and structurally valid language tag.");
50
51 let result = Intl.getCanonicalLocales(tag);
52 assert.sameValue(result.length, 1);
53 assert.sameValue(result[0], canonical);
54 }
55
56 reportCompare(0, 0);