Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Unified Diff: tests/corelib/date_time_test.dart

Issue 10832166: Updated VM and JS versions of Date to allow underflow and overflow. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: clean up unnecessary hoop-jumping Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« runtime/lib/date.dart ('K') | « runtime/lib/date.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/date_time_test.dart
diff --git a/tests/corelib/date_time_test.dart b/tests/corelib/date_time_test.dart
index 7524ef3b7a85bf57268aa8f4d6be42d05c43889a..6157fcb7d6efe5bb02dc50d57872e4d791fbfd4f 100644
--- a/tests/corelib/date_time_test.dart
+++ b/tests/corelib/date_time_test.dart
@@ -1,4 +1,4 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -265,12 +265,6 @@ class DateTest {
Expect.throws(() => new Date(dt.year, dt.month, dt.day,
dt.hour, dt.minute, 0, 1));
dt = new Date.fromMillisecondsSinceEpoch(-8640000000000000);
- // TODO(floitsch): Update comment after refactoring.
- // This test currently fails because the arguments must not be negative.
- // However we are going to allow negative (and overflowing) arguments and
- // this line will then throw for the correct reason.
- Expect.throws(() => new Date(dt.year, dt.month, dt.day,
- dt.hour, dt.minute, 0, -1));
floitsch 2012/08/15 08:44:26 This test should still fail. It failed because of
dominich 2012/08/17 16:38:33 Done.
}
static void testUTCGetters() {
@@ -427,6 +421,185 @@ class DateTest {
Expect.equals(false, dt1 == dt2);
}
+ static void testUnderflowAndOverflow() {
+ final dtBase = new Date(2012, 6, 20, 12, 30, 30, 500);
+
+ // Millisecond
+ print(" >>> Millisecond+");
+ var dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
+ dtBase.minute, dtBase.second, 1000);
+ Expect.equals(dtBase.year, dt.year);
+ Expect.equals(dtBase.month, dt.month);
+ Expect.equals(dtBase.day, dt.day);
+ Expect.equals(dtBase.hour, dt.hour);
+ Expect.equals(dtBase.minute, dt.minute);
+ Expect.equals(dtBase.second + 1, dt.second);
+ Expect.equals(0, dt.millisecond);
+
+ print(" >>> Millisecond-");
+ dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
+ dtBase.minute, dtBase.second, -1000);
+ Expect.equals(dtBase.year, dt.year);
+ Expect.equals(dtBase.month, dt.month);
+ Expect.equals(dtBase.day, dt.day);
+ Expect.equals(dtBase.hour, dt.hour);
+ Expect.equals(dtBase.minute, dt.minute);
+ Expect.equals(dtBase.second - 1, dt.second);
+ Expect.equals(0, dt.millisecond);
+
+ // Second
+ print(" >>> Second+");
+ dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
+ dtBase.minute, 60, dtBase.millisecond);
+ Expect.equals(dtBase.year, dt.year);
+ Expect.equals(dtBase.month, dt.month);
+ Expect.equals(dtBase.day, dt.day);
+ Expect.equals(dtBase.hour, dt.hour);
+ Expect.equals(dtBase.minute + 1, dt.minute);
+ Expect.equals(0, dt.second);
+ Expect.equals(dtBase.millisecond, dt.millisecond);
+
+ print(" >>> Second-");
+ dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour,
+ dtBase.minute, -60, dtBase.millisecond);
+ Expect.equals(dtBase.year, dt.year);
+ Expect.equals(dtBase.month, dt.month);
+ Expect.equals(dtBase.day, dt.day);
+ Expect.equals(dtBase.hour, dt.hour);
+ Expect.equals(dtBase.minute - 1, dt.minute);
+ Expect.equals(0, dt.second);
+ Expect.equals(dtBase.millisecond, dt.millisecond);
+
+ // Minute
+ print(" >>> Minute+");
+ dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, 60,
+ dtBase.second, dtBase.millisecond);
+ Expect.equals(dtBase.year, dt.year);
+ Expect.equals(dtBase.month, dt.month);
+ Expect.equals(dtBase.day, dt.day);
+ Expect.equals(dtBase.hour + 1, dt.hour);
+ Expect.equals(0, dt.minute);
+ Expect.equals(dtBase.second, dt.second);
+ Expect.equals(dtBase.millisecond, dt.millisecond);
+
+ print(" >>> Minute-");
+ dt = new Date(dtBase.year, dtBase.month, dtBase.day, dtBase.hour, -60,
+ dtBase.second, dtBase.millisecond);
+ Expect.equals(dtBase.year, dt.year);
+ Expect.equals(dtBase.month, dt.month);
+ Expect.equals(dtBase.day, dt.day);
+ Expect.equals(dtBase.hour - 1, dt.hour);
+ Expect.equals(0, dt.minute);
+ Expect.equals(dtBase.second, dt.second);
+ Expect.equals(dtBase.millisecond, dt.millisecond);
+
+ // Hour
+ print(" >>> Hour+");
+ dt = new Date(dtBase.year, dtBase.month, dtBase.day, 24, dtBase.minute,
+ dtBase.second, dtBase.millisecond);
+ Expect.equals(dtBase.year, dt.year);
+ Expect.equals(dtBase.month, dt.month);
+ Expect.equals(dtBase.day + 1, dt.day);
+ Expect.equals(0, dt.hour);
+ Expect.equals(dtBase.minute, dt.minute);
+ Expect.equals(dtBase.second, dt.second);
+ Expect.equals(dtBase.millisecond, dt.millisecond);
+
+ print(" >>> Hour-");
+ dt = new Date(dtBase.year, dtBase.month, dtBase.day, -24, dtBase.minute,
+ dtBase.second, dtBase.millisecond);
+ Expect.equals(dtBase.year, dt.year);
+ Expect.equals(dtBase.month, dt.month);
+ Expect.equals(dtBase.day - 1, dt.day);
+ Expect.equals(0, dt.hour);
+ Expect.equals(dtBase.minute, dt.minute);
+ Expect.equals(dtBase.second, dt.second);
+ Expect.equals(dtBase.millisecond, dt.millisecond);
+
+ // Day
+ print(" >>> Day+");
+ dt = new Date(dtBase.year, dtBase.month, 31, dtBase.hour, dtBase.minute,
+ dtBase.second, dtBase.millisecond);
+ Expect.equals(dtBase.year, dt.year);
+ Expect.equals(dtBase.month + 1, dt.month);
+ Expect.equals(1, dt.day);
+ Expect.equals(dtBase.hour, dt.hour);
+ Expect.equals(dtBase.minute, dt.minute);
+ Expect.equals(dtBase.second, dt.second);
+ Expect.equals(dtBase.millisecond, dt.millisecond);
+
+ print(" >>> Day-");
+ dt = new Date(dtBase.year, dtBase.month, -30, dtBase.hour, dtBase.minute,
+ dtBase.second, dtBase.millisecond);
+ Expect.equals(dtBase.year, dt.year);
+ Expect.equals(dtBase.month - 1, dt.month);
+ Expect.equals(1, dt.day);
+ Expect.equals(dtBase.hour, dt.hour);
+ Expect.equals(dtBase.minute, dt.minute);
+ Expect.equals(dtBase.second, dt.second);
+ Expect.equals(dtBase.millisecond, dt.millisecond);
+
+ // Month
+ print(" >>> Month+");
+ dt = new Date(dtBase.year, 13, dtBase.day, dtBase.hour, dtBase.minute,
+ dtBase.second, dtBase.millisecond);
+ Expect.equals(dtBase.year + 1, dt.year);
+ Expect.equals(1, dt.month);
+ Expect.equals(dtBase.day, dt.day);
+ Expect.equals(dtBase.hour, dt.hour);
+ Expect.equals(dtBase.minute, dt.minute);
+ Expect.equals(dtBase.second, dt.second);
+ Expect.equals(dtBase.millisecond, dt.millisecond);
+
+ print(" >>> Month-");
+ dt = new Date(dtBase.year, -11, dtBase.day, dtBase.hour, dtBase.minute,
+ dtBase.second, dtBase.millisecond);
+ Expect.equals(dtBase.year - 1, dt.year);
+ Expect.equals(1, dt.month);
+ Expect.equals(dtBase.day, dt.day);
+ Expect.equals(dtBase.hour, dt.hour);
+ Expect.equals(dtBase.minute, dt.minute);
+ Expect.equals(dtBase.second, dt.second);
+ Expect.equals(dtBase.millisecond, dt.millisecond);
+
+ // Flowing all the way up the chain.
+ print(" >>> Flow+");
+ var dtBase1 = new Date(2012, 12, 31, 23, 59, 59, 999);
+ var dtTick = new Date(dtBase1.year, dtBase1.month, dtBase1.day,
+ dtBase1.hour, dtBase1.minute, dtBase1.second,
+ dtBase1.millisecond + 1);
+ Expect.equals(dtBase1.year + 1, dtTick.year);
+ Expect.equals(1, dtTick.month);
+ Expect.equals(1, dtTick.day);
+ Expect.equals(0, dtTick.hour);
+ Expect.equals(0, dtTick.minute);
+ Expect.equals(0, dtTick.second);
+ Expect.equals(0, dtTick.millisecond);
+
+ print(" >>> Flow-");
+ dtBase1 = new Date(2012, 1, 1, 0, 0, 0, 0);
+ dtTick = new Date(dtBase1.year, dtBase1.month, dtBase1.day, dtBase1.hour,
+ dtBase1.minute, dtBase1.second, dtBase1.millisecond - 1);
+ Expect.equals(dtBase1.year - 1, dtTick.year);
+ Expect.equals(12, dtTick.month);
+ Expect.equals(31, dtTick.day);
+ Expect.equals(23, dtTick.hour);
+ Expect.equals(59, dtTick.minute);
+ Expect.equals(59, dtTick.second);
+ Expect.equals(999, dtTick.millisecond);
+
+ print(" >>> extra underflow");
+ dtTick = new Date(dtBase1.year, dtBase1.month, dtBase1.day, -17520,
+ dtBase1.minute, dtBase1.second, dtBase1.millisecond);
+ Expect.equals(dtBase1.year - 2, dtTick.year);
+ Expect.equals(dtBase1.month, dtTick.month);
+ Expect.equals(dtBase1.day, dtTick.day);
+ Expect.equals(dtBase1.hour, dtTick.hour);
+ Expect.equals(dtBase1.minute, dtTick.minute);
+ Expect.equals(dtBase1.second, dtTick.second);
+ Expect.equals(dtBase1.millisecond, dtTick.millisecond);
+ }
+
static void testDateStrings() {
// TODO(floitsch): Clean up the Date API that deals with strings.
var dt1 = new Date.fromString("2011-05-11 18:58:35Z");
@@ -636,6 +809,7 @@ class DateTest {
testLocalGetters();
testChangeTimeZone();
testSubAdd();
+ testUnderflowAndOverflow();
testDateStrings();
testEquivalentYears();
testExtremes();
« runtime/lib/date.dart ('K') | « runtime/lib/date.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698