summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/Locale/constructor-options-language-invalid.js
blob: 512cf1d67e8952a4297f709e1162ab9537a1eeae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2018 André Bargull; Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-intl.locale
description: >
    Checks error cases for the options argument to the Locale
    constructor.
info: |
    Intl.Locale( tag [, options] )
    10. If options is undefined, then
    11. Else
        a. Let options be ? ToObject(options).
    12. Set tag to ? ApplyOptionsToTag(tag, options).

    ApplyOptionsToTag( tag, options )
    ...
    4. If language is not undefined, then
        a. If language does not match the language production, throw a RangeError exception.
    ...

features: [Intl.Locale]
---*/

/*
 language      = 2*3ALPHA            ; shortest ISO 639 code
                 ["-" extlang]       ; sometimes followed by
                                     ; extended language subtags
               / 4ALPHA              ; or reserved for future use
               / 5*8ALPHA            ; or registered language subtag

 extlang       = 3ALPHA              ; selected ISO 639 codes
                 *2("-" 3ALPHA)      ; permanently reserved
*/
const invalidLanguageOptions = [
  "",
  "a",
  "ab7",
  "notalanguage",
  "undefined",

  // Value contains more than just the 'language' production.
  "fr-Latn",
  "fr-FR",
  "sa-vaidika",
  "fr-a-asdf",
  "fr-x-private",

  // Irregular grandfathered language tag.
  "i-klingon",

  // Regular grandfathered language tag.
  "zh-min",
  "zh-min-nan",

  // Reserved with extended language subtag
  "abcd-US",
  "abcde-US",
  "abcdef-US",
  "abcdefg-US",
  "abcdefgh-US",

  7,
];
for (const language of invalidLanguageOptions) {
  assert.throws(RangeError, function() {
    new Intl.Locale("en", {language});
  }, `new Intl.Locale("en", {language: "${language}"}) throws RangeError`);
}

reportCompare(0, 0);