Debian Codegraph @

js/src/tests/test262/intl402/Locale/constructor-options-script-valid.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 Verify valid language option values (various)
8 info: |
9 Intl.Locale( tag [, options] )
10 9. Else,
11 a. Let tag be ? ToString(tag).
12 10. If options is undefined, then
13 11. Else
14 a. Let options be ? ToObject(options).
15 12. Set tag to ? ApplyOptionsToTag(tag, options).
16
17 ApplyOptionsToTag( tag, options )
18 ...
19 5. Let script be ? GetOption(options, "script", "string", undefined, undefined).
20 ...
21 9. If tag matches neither the privateuse nor the grandfathered production, then
22 ...
23 c. If script is not undefined, then
24 i. If tag does not contain a script production, then
25 1. Set tag to the concatenation of the language production of tag, "-", script, and the rest of tag.
26 ii. Else,
27 1. Set tag to tag with the substring corresponding to the script production replaced by the string script.
28
29
30 features: [Intl.Locale]
31 ---*/
32
33 const validScriptOptions = [
34 [null, 'Null'],
35 ['bali', 'Bali'],
36 ['Bali', 'Bali'],
37 ['bALI', 'Bali'],
38 [{ toString() { return 'Brai' } }, 'Brai'],
39 ];
40 for (const [script, expected] of validScriptOptions) {
41 let expect = expected ? 'en-' + expected : 'en';
42
43 assert.sameValue(
44 new Intl.Locale('en', { script }).toString(),
45 expect,
46 `new Intl.Locale("en", {script: "${script}"}).toString() returns "${expect}"`
47 );
48
49 expect = (expected ? ('en-' + expected) : 'en') + '-DK';
50 assert.sameValue(
51 new Intl.Locale('en-DK', { script }).toString(),
52 expect,
53 `new Intl.Locale("en-DK", {script: "${script}"}).toString() returns "${expect}"`
54 );
55
56 expect = expected ? ('en-' + expected) : 'en-Cyrl';
57 assert.sameValue(
58 new Intl.Locale('en-Cyrl', { script }).toString(),
59 expect,
60 `new Intl.Locale("en-Cyrl", {script: "${script}"}).toString() returns "${expect}"`
61 );
62 }
63
64 reportCompare(0, 0);