Backed out 3 changesets (bug 1892041) for causing failures on async-module-does-not...
[gecko.git] / js / src / tests / test262 / intl402 / DisplayNames / prototype / of / type-region-invalid.js
blob0fcce4ac7e88aed96aead8ac218af9d1f25b6494
1 // Copyright 2023 Igalia S.L. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-Intl.DisplayNames.prototype.of
5 description: Throws a RangeError for invalid `region` codes
6 info: |
7   12.5.1 CanonicalCodeForDisplayNames ( code )
9   ...
10   2. If type is "region", then
11     a. If code cannot be matched by the unicode_region_subtag Unicode locale nonterminal, throw a RangeError exception.
12     b. Return the ASCII-uppercase of code.
13 features: [Intl.DisplayNames]
14 ---*/
16 // https://unicode.org/reports/tr35/#unicode_region_subtag
17 // unicode_region_subtag        = (alpha{2} | digit{3}) ;
19 var displayNames = new Intl.DisplayNames(undefined, {type: 'region'});
21 assert.throws(RangeError, function() {
22   displayNames.of('00');
23 }, 'insufficient length, numeric');
25 assert.throws(RangeError, function() {
26   displayNames.of('a');
27 }, 'insufficient length, alpha');
29 assert.throws(RangeError, function() {
30   displayNames.of('aaa');
31 }, 'excessive length, alpha');
33 assert.throws(RangeError, function() {
34   displayNames.of('1111');
35 }, 'excessive length, numeric');
37 assert.throws(RangeError, function() {
38   displayNames.of('');
39 }, 'empty string');
41 assert.throws(RangeError, function() {
42   displayNames.of('a01');
43 }, 'mixed alphanumeric (alpha first, length 3)');
45 assert.throws(RangeError, function() {
46   displayNames.of('a1');
47 }, 'mixed alphanumeric (alpha first, length 2)');
49 assert.throws(RangeError, function() {
50   displayNames.of('1a');
51 }, 'mixed alphanumeric (numeric first, length 2)');
53 assert.throws(RangeError, function() {
54   displayNames.of('1a1');
55 }, 'mixed alphanumeric (numeric first, length 3)');
57 assert.throws(RangeError, function() {
58   displayNames.of('-111');
59 }, 'leading separator (dash)');
61 assert.throws(RangeError, function() {
62   displayNames.of('_111');
63 }, 'leading separator (underscore)');
65 assert.throws(RangeError, function() {
66   displayNames.of('111-');
67 }, 'trailing separator (dash)');
69 assert.throws(RangeError, function() {
70   displayNames.of('111-');
71 }, 'trailing separator (underscore)');
73 assert.throws(RangeError, function() {
74   displayNames.of(' aa');
75 }, 'leading space');
77 assert.throws(RangeError, function() {
78   displayNames.of('aa ');
79 }, 'trailing space');
81 assert.throws(RangeError, function() {
82   displayNames.of('a c');
83 }, 'interstitial space');
85 reportCompare(0, 0);