From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../Locale/constructor-options-language-valid.js | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 js/src/tests/test262/intl402/Locale/constructor-options-language-valid.js (limited to 'js/src/tests/test262/intl402/Locale/constructor-options-language-valid.js') 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); -- cgit v1.2.3