Skip to content
Snippets Groups Projects
Unverified Commit a33ccf6b authored by Rick Waldron's avatar Rick Waldron Committed by GitHub
Browse files

Merge pull request #1558 from Ms2ger/Locale-constructor-options

Improve and extend the tests for ApplyOptionsToTag.
parents bd7b77c1 9300187c
No related branches found
No related tags found
No related merge requests found
......@@ -15,15 +15,15 @@ info: |
ApplyOptionsToTag( tag, options )
...
9. If tag matches the langtag production, then
a. If language is not undefined, then
9. If tag matches neither the privateuse nor the grandfathered production, then
b. If language is not undefined, then
i. Set tag to tag with the substring corresponding to the language production replaced by the string language.
features: [Intl.Locale]
---*/
const validLanguageOptions = [
[undefined, "en"],
[undefined, undefined],
[null, "null"],
["zh-cmn", "cmn"],
["ZH-CMN", "cmn"],
......@@ -38,7 +38,19 @@ for (const [language, expected] of validLanguageOptions) {
let options = { language };
assert.sameValue(
new Intl.Locale('en', options).toString(),
expected,
expected || 'en',
`new Intl.Locale('en', options).toString() equals the value of ${expected}`
);
assert.sameValue(
new Intl.Locale('en-US', options).toString(),
(expected || "en") + "-US",
`new Intl.Locale('en-US', options).toString() equals the value of ${expected}-US`
);
assert.sameValue(
new Intl.Locale('en-els', options).toString(),
expected || "en-els",
`new Intl.Locale('en-els', options).toString() equals the value of ${expected}`
);
}
......@@ -17,16 +17,19 @@ info: |
...
7. Let region be ? GetOption(options, "region", "string", undefined, undefined).
...
9. If tag matches the langtag production, then
9. If tag matches neither the privateuse nor the grandfathered production, then
...
c. If region is not undefined, then
d. If region is not undefined, then
i. If tag does not contain a region production, then
1. Set tag to the concatenation of the language production of tag, the substring corresponding to the "-" script production if present, "-", region, and the rest of tag.
ii. Else,
1. Set tag to tag with the substring corresponding to the region production replaced by the string region.
features: [Intl.Locale]
---*/
const validRegionOptions = [
[undefined, undefined],
["FR", "en-FR"],
["554", "en-554"],
[554, "en-554"],
......@@ -35,12 +38,25 @@ for (const [region, expected] of validRegionOptions) {
let options = { region };
assert.sameValue(
new Intl.Locale('en', options).toString(),
expected,
expected || "en",
`new Intl.Locale('en', options).toString() equals the value of ${expected}`
);
assert.sameValue(
new Intl.Locale('en-US', options).toString(),
expected,
expected || "en-US",
`new Intl.Locale('en-US', options).toString() equals the value of ${expected}`
);
assert.sameValue(
new Intl.Locale('en-u-ca-gregory', options).toString(),
(expected || "en") + "-u-ca-gregory",
`new Intl.Locale('en-u-ca-gregory', options).toString() equals the value of ${expected}`
);
assert.sameValue(
new Intl.Locale('en-US-u-ca-gregory', options).toString(),
(expected || "en-US") + "-u-ca-gregory",
`new Intl.Locale('en-US-u-ca-gregory', options).toString() equals the value of ${expected}`
);
}
......@@ -17,9 +17,9 @@ info: |
...
5. Let script be ? GetOption(options, "script", "string", undefined, undefined).
...
9. If tag matches the langtag production, then
9. If tag matches neither the privateuse nor the grandfathered production, then
...
b. If script is not undefined, then
c. If script is not undefined, then
i. If tag does not contain a script production, then
1. Set tag to the concatenation of the language production of tag, "-", script, and the rest of tag.
ii. Else,
......@@ -30,22 +30,30 @@ features: [Intl.Locale]
---*/
const validScriptOptions = [
[null, "en-Null"],
["bali", "en-Bali"],
["Bali", "en-Bali"],
["bALI", "en-BALI"], // TODO REVIEW: is this the correct case regularization?
[{ toString() { return "Brai" } }, "en-Brai"],
[undefined, undefined],
[null, "Null"],
["bali", "Bali"],
["Bali", "Bali"],
["bALI", "BALI"], // TODO REVIEW: is this the correct case regularization?
[{ toString() { return "Brai" } }, "Brai"],
];
for (const [script, expected] of validScriptOptions) {
let options = { script };
assert.sameValue(
new Intl.Locale("en", options).toString(),
expected,
expected ? ("en-" + expected) : "en",
`new Intl.Locale("en", options).toString() equals the value of ${expected}`
);
assert.sameValue(
new Intl.Locale("en-DK", options).toString(),
(expected ? ("en-" + expected) : "en") + "-DK",
`new Intl.Locale("en", options).toString() equals the value of ${expected}`
);
assert.sameValue(
new Intl.Locale("en-Cyrl", options).toString(),
expected,
expected ? ("en-" + expected) : "en-Cyrl",
`new Intl.Locale("en-Cyrl", options).toString() equals the value of ${expected}`
);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment