diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/intl402/Locale/constructor-options-language-valid.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/intl402/Locale/constructor-options-language-valid.js')
-rw-r--r-- | js/src/tests/test262/intl402/Locale/constructor-options-language-valid.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/Locale/constructor-options-language-valid.js b/js/src/tests/test262/intl402/Locale/constructor-options-language-valid.js new file mode 100644 index 0000000000..0f1f0b1e32 --- /dev/null +++ b/js/src/tests/test262/intl402/Locale/constructor-options-language-valid.js @@ -0,0 +1,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); |