Debian Codegraph @

js/src/tests/test262/intl402/Locale/constructor-options-language-invalid.js

raw
1 // Copyright 2018 André Bargull; Igalia, S.L. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-intl.locale
6 description: >
7 Checks error cases for the options argument to the Locale
8 constructor.
9 info: |
10 Intl.Locale( tag [, options] )
11 10. If options is undefined, then
12 11. Else
13 a. Let options be ? ToObject(options).
14 12. Set tag to ? ApplyOptionsToTag(tag, options).
15
16 ApplyOptionsToTag( tag, options )
17 ...
18 4. If language is not undefined, then
19 a. If language does not match the language production, throw a RangeError exception.
20 ...
21
22 features: [Intl.Locale]
23 ---*/
24
25 /*
26 language = 2*3ALPHA ; shortest ISO 639 code
27 ["-" extlang] ; sometimes followed by
28 ; extended language subtags
29 / 4ALPHA ; or reserved for future use
30 / 5*8ALPHA ; or registered language subtag
31
32 extlang = 3ALPHA ; selected ISO 639 codes
33 *2("-" 3ALPHA) ; permanently reserved
34 */
35 const invalidLanguageOptions = [
36 "",
37 "a",
38 "ab7",
39 "notalanguage",
40 "undefined",
41
42 // Value contains more than just the 'language' production.
43 "fr-Latn",
44 "fr-FR",
45 "sa-vaidika",
46 "fr-a-asdf",
47 "fr-x-private",
48
49 // Irregular grandfathered language tag.
50 "i-klingon",
51
52 // Regular grandfathered language tag.
53 "zh-min",
54 "zh-min-nan",
55
56 // Reserved with extended language subtag
57 "abcd-US",
58 "abcde-US",
59 "abcdef-US",
60 "abcdefg-US",
61 "abcdefgh-US",
62
63 7,
64 ];
65 for (const language of invalidLanguageOptions) {
66 assert.throws(RangeError, function() {
67 new Intl.Locale("en", {language});
68 }, `new Intl.Locale("en", {language: "${language}"}) throws RangeError`);
69 }
70
71 reportCompare(0, 0);