Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update firstDay tests to latest spec after PR 79 #4141

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ info: |
Intl.Locale( tag [, options] )

...
x. Let numberingSystem be ? GetOption(options, "firstDayOfWeek", "string", < *"mon"*, *"tue"*, *"wed"*, *"thu"*, *"fri"*, *"sat"*, *"sun"*, *"0"*, *"1"*, *"2"*, *"3"*, *"4"*, *"5"*, *"6"*, *"7"*> , undefined).
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.
...

features: [Intl.Locale,Intl.Locale-info]
Expand All @@ -19,10 +22,7 @@ const invalidFirstDayOfWeekOptions = [
"",
"m",
"mo",
"monday",
true,
false,
null,
"longerThan8Chars",
];
for (const firstDayOfWeek of invalidFirstDayOfWeekOptions) {
assert.throws(RangeError, function() {
Expand Down
33 changes: 24 additions & 9 deletions test/intl402/Locale/constructor-options-firstDayOfWeek-valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ info: |
Intl.Locale( tag [, options] )

...
x. Let numberingSystem be ? GetOption(options, "firstDayOfWeek", "string", < *"mon"*, *"tue"*, *"wed"*, *"thu"*, *"fri"*, *"sat"*, *"sun"*, *"0"*, *"1"*, *"2"*, *"3"*, *"4"*, *"5"*, *"6"*, *"7"*> , undefined).
x. Let firstDay be *undefined*.
x. If fw is not *undefined*, then
x. Set firstDay to !WeekdayToString(fw).
x. Set opt.[[fw]] to firstDay.
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.
...
x. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys).
...
x. Let firstDay be *undefined*.
x. If r.[[fw]] is not *undefined*, then
x. Set firstDay to ! WeekdayToNumber(r.[[fw]]).
x. Set locale.[[FirstDayOfWeek]] to firstDay.
x. Set locale.[[FirstDayOfWeek]] to r.[[fw]].
...

features: [Intl.Locale,Intl.Locale-info]
Expand Down Expand Up @@ -50,6 +47,24 @@ const validFirstDayOfWeekOptions = [
[6, "en-u-fw-sat"],
[7, "en-u-fw-sun"],
[0, "en-u-fw-sun"],
[true, "en-u-fw-true"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FrankYFTang is this one correct? IIRC true is dropped from canonical locales. And that's how v8, SpiderMonkey, and LibJS all behave:

> new Intl.Locale('en-u-fw-true').toString()
"en-u-fw" 

> new Intl.Locale('en-u-fw-false').toString()
"en-u-fw-false"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see that in CanonicalizeUValue, where should I be looking for that behvaiour?

Copy link
Contributor

@trflynn89 trflynn89 Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would fall under step 2, which defers to TR-35.

https://unicode.org/reports/tr35/#Canonical_Unicode_Locale_Identifiers

A unicode_locale_id has canonical syntax when:

  • Any type or tfield value "true" is removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah... that is true

[false, "en-u-fw-false"],
[null, "en-u-fw-null"],
["primidi", "en-u-fw-primidi"],
["duodi", "en-u-fw-duodi"],
["tridi", "en-u-fw-tridi"],
["quartidi", "en-u-fw-quartidi"],
["quintidi", "en-u-fw-quintidi"],
["sextidi", "en-u-fw-sextidi"],
["septidi", "en-u-fw-septidi"],
["octidi", "en-u-fw-octidi"],
["nonidi", "en-u-fw-nonidi"],
["decadi", "en-u-fw-decadi"],
["frank", "en-u-fw-frank"],
["yungfong", "en-u-fw-yungfong"],
["yung-fong", "en-u-fw-yung-fong"],
["tang", "en-u-fw-tang"],
["frank-yung-fong-tang", "en-u-fw-frank-yung-fong-tang"],
];
for (const [firstDayOfWeek, expected] of validFirstDayOfWeekOptions) {
assert.sameValue(
Expand Down
14 changes: 7 additions & 7 deletions test/intl402/Locale/prototype/firstDayOfWeek/valid-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ features: [Intl.Locale,Intl.Locale-info]
---*/

const validIds = [
["en-u-fw-mon", 1],
["en-u-fw-tue", 2],
["en-u-fw-wed", 3],
["en-u-fw-thu", 4],
["en-u-fw-fri", 5],
["en-u-fw-sat", 6],
["en-u-fw-sun", 7],
["en-u-fw-mon", "mon"],
["en-u-fw-tue", "tue"],
["en-u-fw-wed", "wed"],
["en-u-fw-thu", "thu"],
["en-u-fw-fri", "fri"],
["en-u-fw-sat", "sat"],
["en-u-fw-sun", "sun"],
];
for (const [id, expected] of validIds) {
assert.sameValue(
Expand Down
46 changes: 23 additions & 23 deletions test/intl402/Locale/prototype/firstDayOfWeek/valid-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ features: [Intl.Locale,Intl.Locale-info]
---*/

const validFirstDayOfWeekOptions = [
["mon", 1],
["tue", 2],
["wed", 3],
["thu", 4],
["fri", 5],
["sat", 6],
["sun", 7],
["1", 1],
["2", 2],
["3", 3],
["4", 4],
["5", 5],
["6", 6],
["7", 7],
["0", 7],
[1, 1],
[2, 2],
[3, 3],
[4, 4],
[5, 5],
[6, 6],
[7, 7],
[0, 7],
["mon", "mon"],
["tue", "tue"],
["wed", "wed"],
["thu", "thu"],
["fri", "fri"],
["sat", "sat"],
["sun", "sun"],
["1", "mon"],
["2", "tue"],
["3", "wed"],
["4", "thu"],
["5", "fri"],
["6", "sat"],
["7", "sun"],
["0", "sun"],
[1, "mon"],
[2, "tue"],
[3, "wed"],
[4, "thu"],
[5, "fri"],
[6, "sat"],
[7, "sun"],
[0, "sun"],
];
for (const [firstDayOfWeek, expected] of validFirstDayOfWeekOptions) {
assert.sameValue(
Expand Down
Loading