From 1e2cfa3fcf790d5cc1e3a87d219107dfc07907a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Thu, 9 Apr 2026 10:00:14 +0200 Subject: [PATCH] Extend coverage for Intl.Locale firstDayOfWeek In "constructor-options-firstDayOfWeek-invalid.js": - Test strings containing non-ASCII alphanum characters - Test numbers and bigints smaller than 0 and larger than 7. - Test fractional numbers and negative Infinity. In "constructor-options-firstDayOfWeek-valid.js": - Test more numbers and also bigints. - Test NaN and positive Infinity. - Test the string `"yes"` as a special-case. - Test upper case strings. In "firstDayOfWeek/valid-id.js": - Test not just the known weekdays, but also additional strings. - Include special cases: empty string, `"true"`, and `"yes"`. - Test number-only strings. - Test upper case strings. In "firstDayOfWeek/valid-options.js": - Test options added to "constructor-options-firstDayOfWeek-valid.js". - Test upper case strings. Drive-by change: - Use `"` consistently for string values. --- ...structor-options-firstDayOfWeek-invalid.js | 31 +++++++++++--- ...onstructor-options-firstDayOfWeek-valid.js | 41 +++++++++++++++---- .../prototype/firstDayOfWeek/valid-id.js | 22 +++++++++- .../prototype/firstDayOfWeek/valid-options.js | 32 ++++++++++++++- 4 files changed, 108 insertions(+), 18 deletions(-) diff --git a/test/intl402/Locale/constructor-options-firstDayOfWeek-invalid.js b/test/intl402/Locale/constructor-options-firstDayOfWeek-invalid.js index 727134d7f93..19b586f8060 100644 --- a/test/intl402/Locale/constructor-options-firstDayOfWeek-invalid.js +++ b/test/intl402/Locale/constructor-options-firstDayOfWeek-invalid.js @@ -9,10 +9,10 @@ info: | Intl.Locale( tag [, options] ) ... - x. Let fw be ? GetOption(options, "firstDayOfWeek", "string", undefined, undefined). - x. If fw is not undefined, then - x. Set fw to !WeekdayToString(fw). - x. If fw does not match the type sequence (from UTS 35 Unicode Locale Identifier, section 3.2), throw a RangeError exception. + 22. Let fw be ? GetOption(options, "firstDayOfWeek", string, empty, undefined). + 23. If fw is not undefined, then + a. Set fw to WeekdayToUValue(fw). + b. If fw cannot be matched by the type Unicode locale nonterminal, throw a RangeError exception. ... features: [Intl.Locale,Intl.Locale-info] @@ -23,9 +23,30 @@ const invalidFirstDayOfWeekOptions = [ "m", "mo", "longerThan8Chars", + "abc\0abc", + "abc?", + "äöü", + "\u6161bc", + 8, + 9, + 10, + -1, + -10, + -100, + -1000, + 8n, + 9n, + 10n, + -1n, + -10n, + -100n, + -1000n, + 0.5, + Number.MIN_VALUE, + -Infinity, ]; for (const firstDayOfWeek of invalidFirstDayOfWeekOptions) { assert.throws(RangeError, function() { - new Intl.Locale('en', {firstDayOfWeek}); + new Intl.Locale("en", {firstDayOfWeek}); }, `new Intl.Locale("en", {firstDayOfWeek: "${firstDayOfWeek}"}) throws RangeError`); } diff --git a/test/intl402/Locale/constructor-options-firstDayOfWeek-valid.js b/test/intl402/Locale/constructor-options-firstDayOfWeek-valid.js index 0c60306257c..723a822047d 100644 --- a/test/intl402/Locale/constructor-options-firstDayOfWeek-valid.js +++ b/test/intl402/Locale/constructor-options-firstDayOfWeek-valid.js @@ -9,15 +9,15 @@ info: | Intl.Locale( tag [, options] ) ... - x. Let fw be ? GetOption(options, "firstDayOfWeek", "string", undefined, undefined). - x. If fw is not undefined, then - x. Set fw to !WeekdayToString(fw). - x. If fw does not match the type sequence (from UTS 35 Unicode Locale Identifier, section 3.2), throw a RangeError exception. - x. Set opt.[[fw]] to fw. + 22. Let fw be ? GetOption(options, "firstDayOfWeek", string, empty, undefined). + 23. If fw is not undefined, then + a. Set fw to WeekdayToUValue(fw). + b. If fw cannot be matched by the type Unicode locale nonterminal, throw a RangeError exception. + 24. Set opt.[[fw]] to fw. ... - x. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys). + 35. Let r be MakeLocaleRecord(tag, opt, localeExtensionKeys). ... - x. Set locale.[[FirstDayOfWeek]] to r.[[fw]]. + 39. Set locale.[[FirstDayOfWeek]] to r.[[fw]]. ... features: [Intl.Locale,Intl.Locale-info] @@ -47,9 +47,25 @@ const validFirstDayOfWeekOptions = [ [6, "en-u-fw-sat"], [7, "en-u-fw-sun"], [0, "en-u-fw-sun"], + [-0, "en-u-fw-sun"], + [100, "en-u-fw-100"], + [1000, "en-u-fw-1000"], + [1n, "en-u-fw-mon"], + [2n, "en-u-fw-tue"], + [3n, "en-u-fw-wed"], + [4n, "en-u-fw-thu"], + [5n, "en-u-fw-fri"], + [6n, "en-u-fw-sat"], + [7n, "en-u-fw-sun"], + [0n, "en-u-fw-sun"], + [100n, "en-u-fw-100"], + [1000n, "en-u-fw-1000"], + [NaN, "en-u-fw-nan"], + [Infinity, "en-u-fw-infinity"], [true, "en-u-fw"], [false, "en-u-fw-false"], [null, "en-u-fw-null"], + ["yes", "en-u-fw-yes"], ["primidi", "en-u-fw-primidi"], ["duodi", "en-u-fw-duodi"], ["tridi", "en-u-fw-tridi"], @@ -68,13 +84,20 @@ const validFirstDayOfWeekOptions = [ ]; for (const [firstDayOfWeek, expected] of validFirstDayOfWeekOptions) { assert.sameValue( - new Intl.Locale('en', { firstDayOfWeek }).toString(), + new Intl.Locale("en", { firstDayOfWeek }).toString(), expected, `new Intl.Locale("en", { firstDayOfWeek: ${firstDayOfWeek} }).toString() returns "${expected}"` ); assert.sameValue( - new Intl.Locale('en-u-fw-WED', { firstDayOfWeek }).toString(), + new Intl.Locale("en-u-fw-WED", { firstDayOfWeek }).toString(), expected, `new Intl.Locale("en-u-fw-WED", { firstDayOfWeek: ${firstDayOfWeek} }).toString() returns "${expected}"` ); + + let upperCase = String(firstDayOfWeek).toUpperCase(); + assert.sameValue( + new Intl.Locale("en", { firstDayOfWeek: upperCase }).toString(), + expected, + `new Intl.Locale("en", { firstDayOfWeek: ${upperCase} }).toString() returns "${expected}"` + ); } diff --git a/test/intl402/Locale/prototype/firstDayOfWeek/valid-id.js b/test/intl402/Locale/prototype/firstDayOfWeek/valid-id.js index d9aa88a33ba..0df2b4bea9b 100644 --- a/test/intl402/Locale/prototype/firstDayOfWeek/valid-id.js +++ b/test/intl402/Locale/prototype/firstDayOfWeek/valid-id.js @@ -4,7 +4,7 @@ /*--- esid: sec-intl.locale description: > - Checks valid cases for the options argument to the Locale constructor. + Checks valid cases for the locale argument to the Locale constructor. info: | Intl.Locale.prototype.firstDayOfWeek 3. Return loc.[[FirstDayOfWeek]]. @@ -20,11 +20,29 @@ const validIds = [ ["en-u-fw-fri", "fri"], ["en-u-fw-sat", "sat"], ["en-u-fw-sun", "sun"], + + ["en-u-fw", ""], + ["en-u-fw-true", ""], + ["en-u-fw-false", "false"], + ["en-u-fw-yes", "yes"], + ["en-u-fw-lunedi", "lunedi"], + ["en-u-fw-montag", "montag"], + + ["en-u-fw-000", "000"], + ["en-u-fw-001", "001"], + ["en-u-fw-11111111", "11111111"], ]; for (const [id, expected] of validIds) { assert.sameValue( new Intl.Locale(id).firstDayOfWeek, expected, - `new Intl.Locale(${id}).firstDayOfWeek returns "${expected}"` + `new Intl.Locale("${id}").firstDayOfWeek returns "${expected}"` + ); + + let upperCase = id.toUpperCase(); + assert.sameValue( + new Intl.Locale(upperCase).firstDayOfWeek, + expected, + `new Intl.Locale("${upperCase}").firstDayOfWeek returns "${expected}"` ); } diff --git a/test/intl402/Locale/prototype/firstDayOfWeek/valid-options.js b/test/intl402/Locale/prototype/firstDayOfWeek/valid-options.js index bf6c8507cc5..5dd0ba2342f 100644 --- a/test/intl402/Locale/prototype/firstDayOfWeek/valid-options.js +++ b/test/intl402/Locale/prototype/firstDayOfWeek/valid-options.js @@ -36,16 +36,44 @@ const validFirstDayOfWeekOptions = [ [6, "sat"], [7, "sun"], [0, "sun"], + [-0, "sun"], + [100, "100"], + [1000, "1000"], + [1n, "mon"], + [2n, "tue"], + [3n, "wed"], + [4n, "thu"], + [5n, "fri"], + [6n, "sat"], + [7n, "sun"], + [0n, "sun"], + [100n, "100"], + [1000n, "1000"], + [NaN, "nan"], + [Infinity, "infinity"], + [true, ""], + [false, "false"], + [null, "null"], + ["yes", "yes"], + ["lunedi", "lunedi"], + ["montag", "montag"], ]; for (const [firstDayOfWeek, expected] of validFirstDayOfWeekOptions) { assert.sameValue( - new Intl.Locale('en', { firstDayOfWeek }).firstDayOfWeek, + new Intl.Locale("en", { firstDayOfWeek }).firstDayOfWeek, expected, `new Intl.Locale("en", { firstDayOfWeek: ${firstDayOfWeek} }).firstDayOfWeek returns "${expected}"` ); assert.sameValue( - new Intl.Locale('en-u-fw-WED', { firstDayOfWeek }).firstDayOfWeek, + new Intl.Locale("en-u-fw-WED", { firstDayOfWeek }).firstDayOfWeek, expected, `new Intl.Locale("en-u-fw-WED", { firstDayOfWeek: ${firstDayOfWeek} }).firstDayOfWeek returns "${expected}"` ); + + let upperCase = String(firstDayOfWeek).toUpperCase(); + assert.sameValue( + new Intl.Locale("en", { firstDayOfWeek: upperCase }).firstDayOfWeek, + expected, + `new Intl.Locale("en", { firstDayOfWeek: ${upperCase} }).firstDayOfWeek returns "${expected}"` + ); }