Improve and extend the tests for ApplyOptionsToTag.

This commit is contained in:
Ms2ger 2018-05-15 14:37:31 +02:00
parent 40883f4c6a
commit 9300187c75
3 changed files with 53 additions and 17 deletions

View File

@ -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}`
);
}

View File

@ -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}`
);
}

View File

@ -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}`
);
}