Debian Codegraph @

js/src/tests/test262/intl402/Intl/getCanonicalLocales/unicode-ext-key-with-digit.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 Unicode extension subtags where the ukey subtag contains a digit.
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 // Unicode locale extension sequences don't allow keys with a digit as their
27 // second character.
28 const invalidCases = [
29 "en-u-c0",
30 "en-u-00",
31 ];
32
33 // The first character is allowed to be a digit.
34 const validCases = [
35 "en-u-0c",
36 ];
37
38 for (let invalid of invalidCases) {
39 // Make sure the test data is correct.
40 assert.sameValue(isCanonicalizedStructurallyValidLanguageTag(invalid), false,
41 "\"" + invalid + "\" isn't a structurally valid language tag.");
42
43 assert.throws(RangeError, () => Intl.getCanonicalLocales(invalid));
44 }
45
46 for (let valid of validCases) {
47 // Make sure the test data is correct.
48 assert(isCanonicalizedStructurallyValidLanguageTag(valid),
49 "\"" + valid + "\" is a canonical and structurally valid language tag.");
50
51 let result = Intl.getCanonicalLocales(valid);
52 assert.sameValue(result.length, 1);
53 assert.sameValue(result[0], valid);
54 }
55
56 reportCompare(0, 0);