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
|
// 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: >
Verify valid language option values (various)
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 )
...
2. If IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
3. Let language be ? GetOption(options, "language", "string", undefined, undefined).
4. If language is not undefined, then
a. If language does not match the unicode_language_subtag production, throw a RangeError exception.
IsStructurallyValidLanguageTag ( locale )
The IsStructurallyValidLanguageTag abstract operation verifies that the
locale argument (which must be a String value)
represents a well-formed Unicode BCP 47 Locale Identifier" as specified in
Unicode Technical Standard 35 section 3.2, or successor,
features: [Intl.Locale]
---*/
const validLanguageOptions = [
[{ toString() { return 'de' } }, 'de'],
];
for (const [language, expected] of validLanguageOptions) {
let expect = expected || 'en';
assert.sameValue(
new Intl.Locale('en', {language}).toString(),
expect,
`new Intl.Locale('en', {language: "${language}"}).toString() returns "${expect}"`
);
expect = (expected || 'en') + '-US';
assert.sameValue(
new Intl.Locale('en-US', {language}).toString(),
expect,
`new Intl.Locale('en-US', {language: "${language}"}).toString() returns "${expect}"`
);
assert.throws(RangeError, () => new Intl.Locale('en-els', {language}));
}
const invalidLanguageOptions = [
null,
'zh-cmn',
'ZH-CMN',
'abcd',
];
for (const language of invalidLanguageOptions) {
assert.throws(RangeError, () => new Intl.Locale('en', {language}));
assert.throws(RangeError, () => new Intl.Locale('en-US', {language}));
assert.throws(RangeError, () => new Intl.Locale('en-els', {language}));
}
reportCompare(0, 0);
|