Debian Codegraph @

js/src/tests/test262/intl402/Locale/constructor-options-region-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 8. If region is not undefined, then
19 a. If region does not match the region production, throw a RangeError exception.
20 ...
21
22 features: [Intl.Locale]
23 ---*/
24
25 /*
26 region = 2ALPHA ; ISO 3166-1 code
27 / 3DIGIT ; UN M.49 code
28 */
29 const invalidRegionOptions = [
30 "",
31 "a",
32 "abc",
33 "a7",
34
35 // Value cannot be parsed as a 'region' production.
36 "notaregion",
37
38 // Value contains more than just the 'region' production.
39 "SA-vaidika",
40 "SA-a-asdf",
41 "SA-x-private",
42
43 // Value contains more than just the 'script' production.
44 "ary-Arab",
45 "Latn-SA",
46 "Latn-vaidika",
47 "Latn-a-asdf",
48 "Latn-x-private",
49
50 7,
51 ];
52 for (const region of invalidRegionOptions) {
53 assert.throws(RangeError, function() {
54 new Intl.Locale("en", {region});
55 }, `new Intl.Locale("en", {region: "${region}"}) throws RangeError`);
56 }
57
58 reportCompare(0, 0);