Debian Codegraph @

js/src/tests/non262/Intl/extensions/unicode-extension-sequences.js

raw
1 // |reftest| skip-if(!this.getSelfHostedValue||!this.hasOwnProperty('Intl'))
2
3 const startOfUnicodeExtensions = getSelfHostedValue("startOfUnicodeExtensions");
4 const endOfUnicodeExtensions = getSelfHostedValue("endOfUnicodeExtensions");
5
6 const testcases = [
7 // Language tag without Unicode extension.
8 { locale: "en", start: -1, end: 0 },
9 { locale: "en-Latn", start: -1, end: 0 },
10 { locale: "en-x-y", start: -1, end: 0 },
11 { locale: "en-x-yz", start: -1, end: 0 },
12 { locale: "en-x-u-kf", start: -1, end: 0 },
13
14 // Unicode extension sequence starts with key subtag.
15 // - no suceeding key or type subtags.
16 { locale: "en-u-ab", start: 2, end: 7 },
17 { locale: "en-u-ab-x-y", start: 2, end: 7 },
18 { locale: "en-u-ab-x-yz", start: 2, end: 7 },
19 { locale: "en-u-ab-x-u-kn", start: 2, end: 7 },
20 // - followed by key subtag.
21 { locale: "en-u-ab-cd", start: 2, end: 10 },
22 { locale: "en-u-ab-cd-x-y", start: 2, end: 10 },
23 { locale: "en-u-ab-cd-x-yz", start: 2, end: 10 },
24 { locale: "en-u-ab-cd-x-u-kn", start: 2, end: 10 },
25 // - followed by type subtag.
26 { locale: "en-u-ab-cdef", start: 2, end: 12 },
27 { locale: "en-u-ab-cdef-x-y", start: 2, end: 12 },
28 { locale: "en-u-ab-cdef-x-yz", start: 2, end: 12 },
29 { locale: "en-u-ab-cdef-x-y-u-kn", start: 2, end: 12 },
30
31 // Unicode extension sequence starts with attribute subtag.
32 // - no suceeding attribute or key subtags.
33 { locale: "en-u-abc", start: 2, end: 8 },
34 { locale: "en-u-abc-x-y", start: 2, end: 8 },
35 { locale: "en-u-abc-x-yz", start: 2, end: 8 },
36 { locale: "en-u-abc-x-y-u-kn", start: 2, end: 8 },
37 // - followed by attribute subtag.
38 { locale: "en-u-abc-def", start: 2, end: 12 },
39 { locale: "en-u-abc-def-x-y", start: 2, end: 12 },
40 { locale: "en-u-abc-def-x-yz", start: 2, end: 12 },
41 { locale: "en-u-abc-def-x-y-u-kn", start: 2, end: 12 },
42 // - followed by key subtag.
43 { locale: "en-u-abc-de", start: 2, end: 11 },
44 { locale: "en-u-abc-de-x-y", start: 2, end: 11 },
45 { locale: "en-u-abc-de-x-yz", start: 2, end: 11 },
46 { locale: "en-u-abc-de-x-y-u-kn", start: 2, end: 11 },
47 // - followed by two key subtags.
48 { locale: "en-u-abc-de-fg", start: 2, end: 14 },
49 { locale: "en-u-abc-de-fg-x-y", start: 2, end: 14 },
50 { locale: "en-u-abc-de-fg-x-yz", start: 2, end: 14 },
51 { locale: "en-u-abc-de-fg-x-y-u-kn", start: 2, end: 14 },
52 // - followed by key and type subtag.
53 { locale: "en-u-abc-de-fgh", start: 2, end: 15 },
54 { locale: "en-u-abc-de-fgh-x-y", start: 2, end: 15 },
55 { locale: "en-u-abc-de-fgh-x-yz", start: 2, end: 15 },
56 { locale: "en-u-abc-de-fgh-x-y-u-kn", start: 2, end: 15 },
57
58 // Also test when the Unicode extension doesn't start at index 2.
59 { locale: "en-Latn-u-kf", start: 7, end: 12 },
60 { locale: "und-u-kf", start: 3, end: 8 },
61 ];
62
63 for (const {locale, start, end} of testcases) {
64 // Ensure the input is a valid language tag.
65 assertEqArray(Intl.getCanonicalLocales(locale), [locale]);
66
67 assertEq(startOfUnicodeExtensions(locale), start);
68
69 if (start >= 0)
70 assertEq(endOfUnicodeExtensions(locale, start), end);
71 }
72
73 if (typeof reportCompare === "function")
74 reportCompare(true, true);