summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/Intl/getCanonicalLocales/transformed-ext-invalid.js
blob: 2a278ce2b3301b00f78f7c05eee2fd0ca2bf9d54 (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
72
73
74
75
76
77
78
79
80
// Copyright (C) 2020 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-intl.getcanonicallocales
description: >
  A RangeError is thrown when a language tag includes an invalid transformed extension subtag.
info: |
  8.2.1 Intl.getCanonicalLocales (locales)
    1. Let ll be ? CanonicalizeLocaleList(locales).
    2. Return CreateArrayFromList(ll).

  9.2.1 CanonicalizeLocaleList (locales)
    ...
    7. Repeat, while k < len
      ...
      c. If kPresent is true, then
        ...
        v. If IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
        ...

includes: [testIntl.js]
---*/

const invalid = [
  // empty
  "en-t",
  "en-t-a",
  "en-t-x",
  "en-t-0",

  // incomplete
  "en-t-",
  "en-t-en-",
  "en-t-0x-",

  // tlang: unicode_language_subtag must be 2-3 or 5-8 characters and mustn't
  // contain extlang subtags.
  "en-t-root",
  "en-t-abcdefghi",
  "en-t-ar-aao",

  // tlang: unicode_script_subtag must be 4 alphabetical characters, can't
  // be repeated.
  "en-t-en-lat0",
  "en-t-en-latn-latn",

  // tlang: unicode_region_subtag must either be 2 alpha characters or a three
  // digit code.
  "en-t-en-0",
  "en-t-en-00",
  "en-t-en-0x",
  "en-t-en-x0",
  "en-t-en-latn-0",
  "en-t-en-latn-00",
  "en-t-en-latn-xyz",

  // tlang: unicode_variant_subtag is either 5-8 alphanum characters or 4
  // characters starting with a digit.
  "en-t-en-abcdefghi",
  "en-t-en-latn-gb-ab",
  "en-t-en-latn-gb-abc",
  "en-t-en-latn-gb-abcd",
  "en-t-en-latn-gb-abcdefghi",

  // tkey must be followed by tvalue.
  "en-t-d0",
  "en-t-d0-m0",
  "en-t-d0-x-private",
];

for (let tag of invalid) {
  // Make sure the test data is correct.
  assert.sameValue(isCanonicalizedStructurallyValidLanguageTag(tag), false,
                   "\"" + tag + "\" isn't a structurally valid language tag.");

  assert.throws(RangeError, () => Intl.getCanonicalLocales(tag), `${tag}`);
}

reportCompare(0, 0);