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

Test normative changes in ECMA-402 #715 #3679

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
@@ -1,4 +1,5 @@
// Copyright 2019 Google Inc. All rights reserved.
// Copyright (C) 2022 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
Expand All @@ -7,7 +8,8 @@ description: >
Checks error cases for the options argument to the DateTimeFormat constructor.
info: |
InitializeDateTimeFormat ( dateTimeFormat, locales, options )
23. Let _opt_.[[FractionalSecondDigits]] be ? GetNumberOption(_options_, `"fractionalSecondDigits"`, 0, 3, 0).
1. Let _value_ be ? GetNumberOption(_options_, *"fractionalSecondDigits"*, 0, 9, *undefined*).
1. If _value_ is one of *"0"*, *"4"*, *"5"*, *"6"*, *"7"*, *"8"*, *"9"*, set _value_ to *undefined*.
Copy link
Contributor

Choose a reason for hiding this comment

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

(See my comment in the ECMA-402 PR about this line of the spec text)


...
features: [Intl.DateTimeFormat-fractionalSecondDigits]
Expand All @@ -21,11 +23,8 @@ const invalidOptions = [
"full",
"numeric",
-1,
4,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend replacing the removed lines with new values that are still invalid. E.g. 10, "10", and 9.000001.

"4",
"-1",
-0.00001,
3.000001,
-0.00001
];
for (const fractionalSecondDigits of invalidOptions) {
assert.throws(RangeError, function() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2019 Google Inc. All rights reserved.
// Copyright (C) 2022 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
Expand All @@ -7,13 +8,28 @@ description: >
Checks handling of the options argument to the DateTimeFormat constructor.
info: |
InitializeDateTimeFormat ( dateTimeFormat, locales, options )
23. Let _opt_.[[FractionalSecondDigits]] be ? GetNumberOption(_options_, `"fractionalSecondDigits"`, 0, 3, 0).
1. Let _value_ be ? GetNumberOption(_options_, *"fractionalSecondDigits"*, 0, 9, *undefined*).
1. If _value_ is one of *"0"*, *"4"*, *"5"*, *"6"*, *"7"*, *"8"*, *"9"*, set _value_ to *undefined*.
features: [Intl.DateTimeFormat-fractionalSecondDigits]
---*/


const validOptions = [
[undefined, undefined],
[0, undefined],
["0", undefined],
[4, undefined],
["4", undefined],
[5, undefined],
["5", undefined],
[6, undefined],
["6", undefined],
[7, undefined],
["7", undefined],
[8, undefined],
["8", undefined],
[9, undefined],
["9", undefined],
[1, 1],
["1", 1],
[2, 2],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2019 Google Inc. All rights reserved.
// Copyright (C) 2022 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
Expand All @@ -12,12 +13,16 @@ const d1 = new Date(2019, 7, 10, 1, 2, 3, 234);
const d2 = new Date(2019, 7, 10, 1, 2, 3, 567);
const d3 = new Date(2019, 7, 10, 1, 2, 13, 987);

let dtf = new Intl.DateTimeFormat(
'en', { minute: "numeric", second: "numeric", fractionalSecondDigits: undefined});
assert.sameValue(dtf.formatRange(d1, d2), "02:03", "no fractionalSecondDigits");
assert.sameValue(dtf.formatRange(d1, d3), "02:03 – 02:13", "no fractionalSecondDigits");
[undefined, 0, 4, 5, 6, 7, 8, 9, "0", "4", "5", "6", "7", "8", "9"].forEach((fractionalSecondDigits)=>{

dtf = new Intl.DateTimeFormat(
let dtf = new Intl.DateTimeFormat(
'en', { minute: "numeric", second: "numeric", fractionalSecondDigits });
assert.sameValue(dtf.formatRange(d1, d2), "02:03", "no fractionalSecondDigits");
assert.sameValue(dtf.formatRange(d1, d3), "02:03 – 02:13", "no fractionalSecondDigits");

});

let dtf = new Intl.DateTimeFormat(
'en', { minute: "numeric", second: "numeric", fractionalSecondDigits: 1});
assert.sameValue(dtf.formatRange(d1, d2), "02:03.2 – 02:03.5", "1 fractionalSecondDigits round down");
assert.sameValue(dtf.formatRange(d1, d3), "02:03.2 – 02:13.9", "1 fractionalSecondDigits round down");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2020 Google Inc, Igalia S.L. All rights reserved.
// Copyright (C) 2022 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
Expand Down Expand Up @@ -27,36 +28,32 @@ const d1 = new Date(2019, 7, 10, 1, 2, 3, 234);
const d2 = new Date(2019, 7, 10, 1, 2, 3, 567);
const d3 = new Date(2019, 7, 10, 1, 2, 13, 987);

assert.throws(RangeError, () => {
new Intl.DateTimeFormat(
'en', { minute: "numeric", second: "numeric", fractionalSecondDigits: 0});
}, "fractionalSecondDigits 0 should throw RangeError for out of range");
Comment on lines -30 to -33
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend keeping these out-of-range tests but changing the values from 0 and 4, to -1 and 10.

[undefined, 0, 4, 5, 6, 7, 8, 9, "0", "4", "5", "6", "7", "8", "9"].forEach((fractionalSecondDigits)=>{

assert.throws(RangeError, () => {
new Intl.DateTimeFormat(
'en', { minute: "numeric", second: "numeric", fractionalSecondDigits: 4});
}, "fractionalSecondDigits 4 should throw RangeError for out of range");
let dtf = new Intl.DateTimeFormat(
'en', { minute: "numeric", second: "numeric", fractionalSecondDigits });

let dtf = new Intl.DateTimeFormat(
'en', { minute: "numeric", second: "numeric", fractionalSecondDigits: undefined});
compare(dtf.formatRangeToParts(d1, d2), [
{ type: "minute", value: "02", source: "shared" },
{ type: "literal", value: ":", source: "shared" },
{ type: "second", value: "03", source: "shared" }
]);

compare(dtf.formatRangeToParts(d1, d2), [
{ type: "minute", value: "02", source: "shared" },
{ type: "literal", value: ":", source: "shared" },
{ type: "second", value: "03", source: "shared" }
]);
compare(dtf.formatRangeToParts(d1, d3), [
{ type: "minute", value: "02", source: "startRange" },
{ type: "literal", value: ":", source: "startRange" },
{ type: "second", value: "03", source: "startRange" },
{ type: "literal", value: " \u2013 ", source: "shared" },
{ type: "minute", value: "02", source: "endRange" },
{ type: "literal", value: ":", source: "endRange" },
{ type: "second", value: "13", source: "endRange" }
]);

compare(dtf.formatRangeToParts(d1, d3), [
{ type: "minute", value: "02", source: "startRange" },
{ type: "literal", value: ":", source: "startRange" },
{ type: "second", value: "03", source: "startRange" },
{ type: "literal", value: " \u2013 ", source: "shared" },
{ type: "minute", value: "02", source: "endRange" },
{ type: "literal", value: ":", source: "endRange" },
{ type: "second", value: "13", source: "endRange" }
]);
});

dtf = new Intl.DateTimeFormat(


let dtf = new Intl.DateTimeFormat(
'en', { minute: "numeric", second: "numeric", fractionalSecondDigits: 1});

compare(dtf.formatRangeToParts(d1, d2), [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2019 Google Inc. All rights reserved.
// Copyright (C) 2022 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
Expand Down Expand Up @@ -31,15 +32,6 @@ function assertParts(parts, minute, second, fractionalSecond, message) {
}
}

assert.throws(RangeError, () => {
new Intl.DateTimeFormat(
'en', { minute: "numeric", second: "numeric", fractionalSecondDigits: 0});
}, "fractionalSecondDigits 0 should throw RangeError for out of range");

assert.throws(RangeError, () => {
new Intl.DateTimeFormat(
'en', { minute: "numeric", second: "numeric", fractionalSecondDigits: 4});
}, "fractionalSecondDigits 4 should throw RangeError for out of range");
Comment on lines -34 to -42
Copy link
Contributor

Choose a reason for hiding this comment

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

Same, I'd recommend testing -1 and 10.


let dtf = new Intl.DateTimeFormat(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this one test the same values that you're looping over in the other test files? (undefined, 0, "0", etc)

'en', { minute: "numeric", second: "numeric"});
Expand Down