Skip to content

Commit f41d6de

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
[corelib_2] Split date_time_test to increase coverage
After moving ~175 lines to other files, the remaining ~1200 lines of tests in date_time_test.dart passes on dart2js. Change-Id: Id8366b90083c22f71e5ff2e3f36ac1f0358ec8e2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108220 Reviewed-by: Lasse R.H. Nielsen <[email protected]> Commit-Queue: Stephen Adams <[email protected]>
1 parent 9bccb7b commit f41d6de

File tree

4 files changed

+206
-175
lines changed

4 files changed

+206
-175
lines changed

tests/corelib_2/corelib_2.status

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ bit_twiddling_test/int64: CompileTimeError, OK # Error if web int literal cannot
2020
compare_to2_test: CompileTimeError, OK # Error if web int literal cannot be represented exactly, see http://dartbug.com/33351
2121
core_runtime_types_test: RuntimeError # Issue 34147
2222
date_time11_test: RuntimeError, Pass # Fails when US is on winter time, issue 31285.
23-
date_time_test: CompileTimeError, OK # Error if web int literal cannot be represented exactly, see http://dartbug.com/33351
2423
double_ceil_test/int64: CompileTimeError, OK # Error if web int literal cannot be represented exactly, see http://dartbug.com/33351
2524
double_floor_test/int64: CompileTimeError, OK # Error if web int literal cannot be represented exactly, see http://dartbug.com/33351
2625
double_round_test/int64: CompileTimeError, OK # Error if web int literal cannot be represented exactly, see http://dartbug.com/33351
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "package:expect/expect.dart";
6+
7+
// Dart test program for DateTime, extreme values.
8+
9+
bool get supportsMicroseconds =>
10+
new DateTime.fromMicrosecondsSinceEpoch(1).microsecondsSinceEpoch == 1;
11+
12+
// Identical to _maxMillisecondsSinceEpoch in date_time.dart
13+
const int _MAX_MILLISECONDS = 8640000000000000;
14+
15+
void testExtremes() {
16+
var dt =
17+
new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS, isUtc: true);
18+
Expect.equals(275760, dt.year);
19+
Expect.equals(9, dt.month);
20+
Expect.equals(13, dt.day);
21+
Expect.equals(0, dt.hour);
22+
Expect.equals(0, dt.minute);
23+
Expect.equals(0, dt.second);
24+
Expect.equals(0, dt.millisecond);
25+
Expect.equals(0, dt.microsecond);
26+
dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS, isUtc: true);
27+
Expect.equals(-271821, dt.year);
28+
Expect.equals(4, dt.month);
29+
Expect.equals(20, dt.day);
30+
Expect.equals(0, dt.hour);
31+
Expect.equals(0, dt.minute);
32+
Expect.equals(0, dt.second);
33+
Expect.equals(0, dt.millisecond);
34+
Expect.equals(0, dt.microsecond);
35+
// Make sure that we can build the extreme dates in local too.
36+
dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS);
37+
dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute);
38+
Expect.equals(_MAX_MILLISECONDS, dt.millisecondsSinceEpoch);
39+
dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS);
40+
dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute);
41+
Expect.equals(-_MAX_MILLISECONDS, dt.millisecondsSinceEpoch);
42+
Expect.throws(() => new DateTime.fromMillisecondsSinceEpoch(
43+
_MAX_MILLISECONDS + 1,
44+
isUtc: true));
45+
Expect.throws(() => new DateTime.fromMillisecondsSinceEpoch(
46+
-_MAX_MILLISECONDS - 1,
47+
isUtc: true));
48+
Expect.throws(
49+
() => new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS + 1));
50+
Expect.throws(
51+
() => new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS - 1));
52+
dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS);
53+
Expect.throws(
54+
() => new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 1));
55+
dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS, isUtc: true);
56+
Expect.throws(() =>
57+
new DateTime.utc(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 1));
58+
dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS);
59+
Expect.throws(
60+
() => new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, -1));
61+
dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS, isUtc: true);
62+
Expect.throws(() =>
63+
new DateTime.utc(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, -1));
64+
65+
if (!supportsMicroseconds) return;
66+
67+
dt = new DateTime.fromMicrosecondsSinceEpoch(_MAX_MILLISECONDS * 1000);
68+
dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute);
69+
Expect.equals(_MAX_MILLISECONDS * 1000, dt.microsecondsSinceEpoch);
70+
dt = new DateTime.fromMicrosecondsSinceEpoch(-_MAX_MILLISECONDS * 1000);
71+
dt = new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute);
72+
Expect.equals(-_MAX_MILLISECONDS * 1000, dt.microsecondsSinceEpoch);
73+
Expect.throws(() => new DateTime.fromMicrosecondsSinceEpoch(
74+
_MAX_MILLISECONDS * 1000 + 1,
75+
isUtc: true));
76+
Expect.throws(() => new DateTime.fromMicrosecondsSinceEpoch(
77+
-_MAX_MILLISECONDS * 1000 - 1,
78+
isUtc: true));
79+
Expect.throws(() =>
80+
new DateTime.fromMicrosecondsSinceEpoch(_MAX_MILLISECONDS * 1000 + 1));
81+
Expect.throws(() =>
82+
new DateTime.fromMicrosecondsSinceEpoch(-_MAX_MILLISECONDS * 1000 - 1));
83+
dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS);
84+
Expect.throws(() =>
85+
new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 0, 1));
86+
dt = new DateTime.fromMillisecondsSinceEpoch(_MAX_MILLISECONDS, isUtc: true);
87+
Expect.throws(() =>
88+
new DateTime.utc(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 0, 1));
89+
dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS);
90+
Expect.throws(() =>
91+
new DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 0, -1));
92+
dt = new DateTime.fromMillisecondsSinceEpoch(-_MAX_MILLISECONDS, isUtc: true);
93+
Expect.throws(() => new DateTime.utc(
94+
dt.year, dt.month, dt.day, dt.hour, dt.minute, 0, 0, -1));
95+
}
96+
97+
void main() {
98+
testExtremes();
99+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "package:expect/expect.dart";
6+
7+
// Dart test program for DateTime, far away dates.
8+
9+
// TODO(37442): Find far-away dates with milliseconds-since-epoch values that
10+
// are 'web' integers.
11+
12+
bool get supportsMicroseconds =>
13+
new DateTime.fromMicrosecondsSinceEpoch(1).microsecondsSinceEpoch == 1;
14+
15+
void testFarAwayDates() {
16+
DateTime dt =
17+
new DateTime.fromMillisecondsSinceEpoch(1000000000000001, isUtc: true);
18+
Expect.equals(33658, dt.year);
19+
Expect.equals(9, dt.month);
20+
Expect.equals(27, dt.day);
21+
Expect.equals(1, dt.hour);
22+
Expect.equals(46, dt.minute);
23+
Expect.equals(40, dt.second);
24+
Expect.equals(1, dt.millisecond);
25+
Expect.equals(0, dt.microsecond);
26+
dt = new DateTime.fromMillisecondsSinceEpoch(-1000000000000001, isUtc: true);
27+
Expect.equals(-29719, dt.year);
28+
Expect.equals(4, dt.month);
29+
Expect.equals(5, dt.day);
30+
Expect.equals(22, dt.hour);
31+
Expect.equals(13, dt.minute);
32+
Expect.equals(19, dt.second);
33+
Expect.equals(999, dt.millisecond);
34+
Expect.equals(0, dt.microsecond);
35+
// Same with local zone.
36+
dt = new DateTime.fromMillisecondsSinceEpoch(1000000000000001);
37+
Expect.equals(33658, dt.year);
38+
Expect.equals(9, dt.month);
39+
Expect.equals(true, dt.day == 27 || dt.day == 26);
40+
// Not much we can test for local hour.
41+
Expect.equals(true, dt.hour >= 0 && dt.hour < 24);
42+
// Timezones can have offsets down to 15 minute.
43+
Expect.equals(true, dt.minute % 15 == 46 % 15);
44+
Expect.equals(40, dt.second);
45+
Expect.equals(1, dt.millisecond);
46+
Expect.equals(0, dt.microsecond);
47+
dt = new DateTime.fromMillisecondsSinceEpoch(-1000000000000001);
48+
Expect.equals(-29719, dt.year);
49+
Expect.equals(4, dt.month);
50+
Expect.equals(true, 5 == dt.day || 6 == dt.day);
51+
// Not much we can test for local hour.
52+
Expect.equals(true, dt.hour >= 0 && dt.hour < 24);
53+
// Timezones can have offsets down to 15 minute.
54+
Expect.equals(true, dt.minute % 15 == 13);
55+
Expect.equals(19, dt.second);
56+
Expect.equals(999, dt.millisecond);
57+
Expect.equals(0, dt.microsecond);
58+
59+
if (!supportsMicroseconds) return;
60+
dt =
61+
new DateTime.fromMicrosecondsSinceEpoch(1000000000000000001, isUtc: true);
62+
Expect.equals(33658, dt.year);
63+
Expect.equals(9, dt.month);
64+
Expect.equals(27, dt.day);
65+
Expect.equals(1, dt.hour);
66+
Expect.equals(46, dt.minute);
67+
Expect.equals(40, dt.second);
68+
Expect.equals(0, dt.millisecond);
69+
Expect.equals(1, dt.microsecond);
70+
dt = new DateTime.fromMicrosecondsSinceEpoch(-1000000000000000001,
71+
isUtc: true);
72+
Expect.equals(-29719, dt.year);
73+
Expect.equals(4, dt.month);
74+
Expect.equals(5, dt.day);
75+
Expect.equals(22, dt.hour);
76+
Expect.equals(13, dt.minute);
77+
Expect.equals(19, dt.second);
78+
Expect.equals(999, dt.millisecond);
79+
Expect.equals(999, dt.microsecond);
80+
// Same with local zone.
81+
dt = new DateTime.fromMicrosecondsSinceEpoch(1000000000000000001);
82+
Expect.equals(33658, dt.year);
83+
Expect.equals(9, dt.month);
84+
Expect.equals(true, dt.day == 27 || dt.day == 26);
85+
// Not much we can test for local hour.
86+
Expect.equals(true, dt.hour >= 0 && dt.hour < 24);
87+
// Timezones can have offsets down to 15 minute.
88+
Expect.equals(true, dt.minute % 15 == 46 % 15);
89+
Expect.equals(40, dt.second);
90+
Expect.equals(0, dt.millisecond);
91+
Expect.equals(1, dt.microsecond);
92+
dt = new DateTime.fromMicrosecondsSinceEpoch(-1000000000000000001);
93+
Expect.equals(-29719, dt.year);
94+
Expect.equals(4, dt.month);
95+
Expect.equals(true, 5 == dt.day || 6 == dt.day);
96+
// Not much we can test for local hour.
97+
Expect.equals(true, dt.hour >= 0 && dt.hour < 24);
98+
// Timezones can have offsets down to 15 minute.
99+
Expect.equals(true, dt.minute % 15 == 13);
100+
Expect.equals(19, dt.second);
101+
Expect.equals(999, dt.millisecond);
102+
Expect.equals(999, dt.microsecond);
103+
}
104+
105+
void main() {
106+
testFarAwayDates();
107+
}

0 commit comments

Comments
 (0)