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

Side by Side Diff: tests/standalone/io/http_date_test.dart

Issue 11770004: Rename Date to DateTime. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments and keep Backwards-compatibility class Date. Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "dart:async"; 5 import "dart:async";
6 import "dart:math"; 6 import "dart:math";
7 7
8 part "../../../sdk/lib/io/input_stream.dart"; 8 part "../../../sdk/lib/io/input_stream.dart";
9 part "../../../sdk/lib/io/output_stream.dart"; 9 part "../../../sdk/lib/io/output_stream.dart";
10 part "../../../sdk/lib/io/chunked_stream.dart"; 10 part "../../../sdk/lib/io/chunked_stream.dart";
11 part "../../../sdk/lib/io/string_stream.dart"; 11 part "../../../sdk/lib/io/string_stream.dart";
12 part "../../../sdk/lib/io/stream_util.dart"; 12 part "../../../sdk/lib/io/stream_util.dart";
13 part "../../../sdk/lib/io/http.dart"; 13 part "../../../sdk/lib/io/http.dart";
14 part "../../../sdk/lib/io/http_impl.dart"; 14 part "../../../sdk/lib/io/http_impl.dart";
15 part "../../../sdk/lib/io/http_parser.dart"; 15 part "../../../sdk/lib/io/http_parser.dart";
16 part "../../../sdk/lib/io/http_utils.dart"; 16 part "../../../sdk/lib/io/http_utils.dart";
17 17
18 void testParseHttpDate() { 18 void testParseHttpDate() {
19 Date date; 19 DateTime date;
20 date = new Date.utc(1999, Date.JUN, 11, 18, 46, 53, 0); 20 date = new DateTime.utc(1999, DateTime.JUN, 11, 18, 46, 53, 0);
21 Expect.equals(date, _HttpUtils.parseDate("Fri, 11 Jun 1999 18:46:53 GMT")); 21 Expect.equals(date, _HttpUtils.parseDate("Fri, 11 Jun 1999 18:46:53 GMT"));
22 Expect.equals(date, _HttpUtils.parseDate("Friday, 11-Jun-1999 18:46:53 GMT")); 22 Expect.equals(date, _HttpUtils.parseDate("Friday, 11-Jun-1999 18:46:53 GMT"));
23 Expect.equals(date, _HttpUtils.parseDate("Fri Jun 11 18:46:53 1999")); 23 Expect.equals(date, _HttpUtils.parseDate("Fri Jun 11 18:46:53 1999"));
24 24
25 date = new Date.utc(1970, Date.JAN, 1, 0, 0, 0, 0); 25 date = new DateTime.utc(1970, DateTime.JAN, 1, 0, 0, 0, 0);
26 Expect.equals(date, _HttpUtils.parseDate("Thu, 1 Jan 1970 00:00:00 GMT")); 26 Expect.equals(date, _HttpUtils.parseDate("Thu, 1 Jan 1970 00:00:00 GMT"));
27 Expect.equals(date, 27 Expect.equals(date,
28 _HttpUtils.parseDate("Thursday, 1-Jan-1970 00:00:00 GMT")); 28 _HttpUtils.parseDate("Thursday, 1-Jan-1970 00:00:00 GMT"));
29 Expect.equals(date, _HttpUtils.parseDate("Thu Jan 1 00:00:00 1970")); 29 Expect.equals(date, _HttpUtils.parseDate("Thu Jan 1 00:00:00 1970"));
30 30
31 date = new Date.utc(2012, Date.MAR, 5, 23, 59, 59, 0); 31 date = new DateTime.utc(2012, DateTime.MAR, 5, 23, 59, 59, 0);
32 Expect.equals(date, _HttpUtils.parseDate("Mon, 5 Mar 2012 23:59:59 GMT")); 32 Expect.equals(date, _HttpUtils.parseDate("Mon, 5 Mar 2012 23:59:59 GMT"));
33 Expect.equals(date, _HttpUtils.parseDate("Monday, 5-Mar-2012 23:59:59 GMT")); 33 Expect.equals(date, _HttpUtils.parseDate("Monday, 5-Mar-2012 23:59:59 GMT"));
34 Expect.equals(date, _HttpUtils.parseDate("Mon Mar 5 23:59:59 2012")); 34 Expect.equals(date, _HttpUtils.parseDate("Mon Mar 5 23:59:59 2012"));
35 } 35 }
36 36
37 void testFormatParseHttpDate() { 37 void testFormatParseHttpDate() {
38 test(int year, 38 test(int year,
39 int month, 39 int month,
40 int day, 40 int day,
41 int hours, 41 int hours,
42 int minutes, 42 int minutes,
43 int seconds, 43 int seconds,
44 String expectedFormatted) { 44 String expectedFormatted) {
45 Date date; 45 DateTime date;
46 String formatted; 46 String formatted;
47 date = new Date.utc(year, month, day, hours, minutes, seconds, 0); 47 date = new DateTime.utc(year, month, day, hours, minutes, seconds, 0);
48 formatted = _HttpUtils.formatDate(date); 48 formatted = _HttpUtils.formatDate(date);
49 Expect.equals(expectedFormatted, formatted); 49 Expect.equals(expectedFormatted, formatted);
50 Expect.equals(date, _HttpUtils.parseDate(formatted)); 50 Expect.equals(date, _HttpUtils.parseDate(formatted));
51 } 51 }
52 52
53 test(1999, Date.JUN, 11, 18, 46, 53, "Fri, 11 Jun 1999 18:46:53 GMT"); 53 test(1999, DateTime.JUN, 11, 18, 46, 53, "Fri, 11 Jun 1999 18:46:53 GMT");
54 test(1970, Date.JAN, 1, 0, 0, 0, "Thu, 1 Jan 1970 00:00:00 GMT"); 54 test(1970, DateTime.JAN, 1, 0, 0, 0, "Thu, 1 Jan 1970 00:00:00 GMT");
55 test(2012, Date.MAR, 5, 23, 59, 59, "Mon, 5 Mar 2012 23:59:59 GMT"); 55 test(2012, DateTime.MAR, 5, 23, 59, 59, "Mon, 5 Mar 2012 23:59:59 GMT");
56 } 56 }
57 57
58 void testParseHttpDateFailures() { 58 void testParseHttpDateFailures() {
59 Expect.throws(() { 59 Expect.throws(() {
60 _HttpUtils.parseDate(""); 60 _HttpUtils.parseDate("");
61 }); 61 });
62 String valid = "Mon, 5 Mar 2012 23:59:59 GMT"; 62 String valid = "Mon, 5 Mar 2012 23:59:59 GMT";
63 for (int i = 1; i < valid.length - 1; i++) { 63 for (int i = 1; i < valid.length - 1; i++) {
64 String tmp = valid.substring(0, i); 64 String tmp = valid.substring(0, i);
65 Expect.throws(() { 65 Expect.throws(() {
(...skipping 23 matching lines...) Expand all
89 void testParseHttpCookieDate() { 89 void testParseHttpCookieDate() {
90 Expect.throws(() => _HttpUtils.parseCookieDate("")); 90 Expect.throws(() => _HttpUtils.parseCookieDate(""));
91 91
92 test(int year, 92 test(int year,
93 int month, 93 int month,
94 int day, 94 int day,
95 int hours, 95 int hours,
96 int minutes, 96 int minutes,
97 int seconds, 97 int seconds,
98 String formatted) { 98 String formatted) {
99 Date date = new Date.utc(year, month, day, hours, minutes, seconds, 0); 99 DateTime date = new DateTime.utc(year, month, day, hours, minutes, seconds, 0);
100 Expect.equals(date, _HttpUtils.parseCookieDate(formatted)); 100 Expect.equals(date, _HttpUtils.parseCookieDate(formatted));
101 } 101 }
102 102
103 test(2012, Date.JUN, 19, 14, 15, 01, "tue, 19-jun-12 14:15:01 gmt"); 103 test(2012, DateTime.JUN, 19, 14, 15, 01, "tue, 19-jun-12 14:15:01 gmt");
104 test(2021, Date.JUN, 09, 10, 18, 14, "Wed, 09-Jun-2021 10:18:14 GMT"); 104 test(2021, DateTime.JUN, 09, 10, 18, 14, "Wed, 09-Jun-2021 10:18:14 GMT");
105 test(2021, Date.JAN, 13, 22, 23, 01, "Wed, 13-Jan-2021 22:23:01 GMT"); 105 test(2021, DateTime.JAN, 13, 22, 23, 01, "Wed, 13-Jan-2021 22:23:01 GMT");
106 test(2013, Date.JAN, 15, 21, 47, 38, "Tue, 15-Jan-2013 21:47:38 GMT"); 106 test(2013, DateTime.JAN, 15, 21, 47, 38, "Tue, 15-Jan-2013 21:47:38 GMT");
107 test(1970, Date.JAN, 01, 00, 00, 01, "Thu, 01-Jan-1970 00:00:01 GMT"); 107 test(1970, DateTime.JAN, 01, 00, 00, 01, "Thu, 01-Jan-1970 00:00:01 GMT");
108 } 108 }
109 109
110 void main() { 110 void main() {
111 testParseHttpDate(); 111 testParseHttpDate();
112 testFormatParseHttpDate(); 112 testFormatParseHttpDate();
113 testParseHttpDateFailures(); 113 testParseHttpDateFailures();
114 testParseHttpCookieDate(); 114 testParseHttpCookieDate();
115 } 115 }
OLDNEW
« no previous file with comments | « tests/standalone/io/http_connection_close_test.dart ('k') | tests/standalone/io/http_headers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698