From 9300187c75460c893e42ccd2c8e3e30d0662152c Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 15 May 2018 14:37:31 +0200 Subject: [PATCH] Improve and extend the tests for ApplyOptionsToTag. --- .../constructor-options-language-valid.js | 20 +++++++++++--- .../constructor-options-region-valid.js | 24 ++++++++++++++--- .../constructor-options-script-valid.js | 26 ++++++++++++------- 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/test/intl402/Locale/constructor-options-language-valid.js b/test/intl402/Locale/constructor-options-language-valid.js index bf5c764dd5..4a2be5aa17 100644 --- a/test/intl402/Locale/constructor-options-language-valid.js +++ b/test/intl402/Locale/constructor-options-language-valid.js @@ -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}` + ); } diff --git a/test/intl402/Locale/constructor-options-region-valid.js b/test/intl402/Locale/constructor-options-region-valid.js index 00d4762736..17d0d0b76f 100644 --- a/test/intl402/Locale/constructor-options-region-valid.js +++ b/test/intl402/Locale/constructor-options-region-valid.js @@ -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}` + ); } diff --git a/test/intl402/Locale/constructor-options-script-valid.js b/test/intl402/Locale/constructor-options-script-valid.js index a9c10a4dd1..53564ff7da 100644 --- a/test/intl402/Locale/constructor-options-script-valid.js +++ b/test/intl402/Locale/constructor-options-script-valid.js @@ -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}` ); }