| OLD | NEW |
| 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 #source("../../../runtime/bin/input_stream.dart"); | 5 #source("../../../runtime/bin/input_stream.dart"); |
| 6 #source("../../../runtime/bin/output_stream.dart"); | 6 #source("../../../runtime/bin/output_stream.dart"); |
| 7 #source("../../../runtime/bin/chunked_stream.dart"); | 7 #source("../../../runtime/bin/chunked_stream.dart"); |
| 8 #source("../../../runtime/bin/string_stream.dart"); | 8 #source("../../../runtime/bin/string_stream.dart"); |
| 9 #source("../../../runtime/bin/stream_util.dart"); | 9 #source("../../../runtime/bin/stream_util.dart"); |
| 10 #source("../../../runtime/bin/http.dart"); | 10 #source("../../../runtime/bin/http.dart"); |
| 11 #source("../../../runtime/bin/http_impl.dart"); | 11 #source("../../../runtime/bin/http_impl.dart"); |
| 12 #source("../../../runtime/bin/http_parser.dart"); | 12 #source("../../../runtime/bin/http_parser.dart"); |
| 13 #source("../../../runtime/bin/http_utils.dart"); | 13 #source("../../../runtime/bin/http_utils.dart"); |
| 14 | 14 |
| 15 void testParseHttpDate() { | 15 void testParseHttpDate() { |
| 16 TimeZone utc = new TimeZone.utc(); | |
| 17 Date date; | 16 Date date; |
| 18 date = new Date.withTimeZone(1999, Date.JUN, 11, 18, 46, 53, 0, utc); | 17 date = new Date(1999, Date.JUN, 11, 18, 46, 53, 0, isUtc: true); |
| 19 Expect.equals(date, _HttpUtils.parseDate("Fri, 11 Jun 1999 18:46:53 GMT")); | 18 Expect.equals(date, _HttpUtils.parseDate("Fri, 11 Jun 1999 18:46:53 GMT")); |
| 20 Expect.equals(date, _HttpUtils.parseDate("Friday, 11-Jun-1999 18:46:53 GMT")); | 19 Expect.equals(date, _HttpUtils.parseDate("Friday, 11-Jun-1999 18:46:53 GMT")); |
| 21 Expect.equals(date, _HttpUtils.parseDate("Fri Jun 11 18:46:53 1999")); | 20 Expect.equals(date, _HttpUtils.parseDate("Fri Jun 11 18:46:53 1999")); |
| 22 | 21 |
| 23 date = new Date.withTimeZone(1970, Date.JAN, 1, 0, 0, 0, 0, utc); | 22 date = new Date(1970, Date.JAN, 1, 0, 0, 0, 0, isUtc: true); |
| 24 Expect.equals(date, _HttpUtils.parseDate("Thu, 1 Jan 1970 00:00:00 GMT")); | 23 Expect.equals(date, _HttpUtils.parseDate("Thu, 1 Jan 1970 00:00:00 GMT")); |
| 25 Expect.equals(date, | 24 Expect.equals(date, |
| 26 _HttpUtils.parseDate("Thursday, 1-Jan-1970 00:00:00 GMT")); | 25 _HttpUtils.parseDate("Thursday, 1-Jan-1970 00:00:00 GMT")); |
| 27 Expect.equals(date, _HttpUtils.parseDate("Thu Jan 1 00:00:00 1970")); | 26 Expect.equals(date, _HttpUtils.parseDate("Thu Jan 1 00:00:00 1970")); |
| 28 | 27 |
| 29 date = new Date.withTimeZone(2012, Date.MAR, 5, 23, 59, 59, 0, utc); | 28 date = new Date(2012, Date.MAR, 5, 23, 59, 59, 0, isUtc: true); |
| 30 Expect.equals(date, _HttpUtils.parseDate("Mon, 5 Mar 2012 23:59:59 GMT")); | 29 Expect.equals(date, _HttpUtils.parseDate("Mon, 5 Mar 2012 23:59:59 GMT")); |
| 31 Expect.equals(date, _HttpUtils.parseDate("Monday, 5-Mar-2012 23:59:59 GMT")); | 30 Expect.equals(date, _HttpUtils.parseDate("Monday, 5-Mar-2012 23:59:59 GMT")); |
| 32 Expect.equals(date, _HttpUtils.parseDate("Mon Mar 5 23:59:59 2012")); | 31 Expect.equals(date, _HttpUtils.parseDate("Mon Mar 5 23:59:59 2012")); |
| 33 } | 32 } |
| 34 | 33 |
| 35 void testFormatParseHttpDate() { | 34 void testFormatParseHttpDate() { |
| 36 test(int year, | 35 test(int year, |
| 37 int month, | 36 int month, |
| 38 int day, | 37 int day, |
| 39 int hours, | 38 int hours, |
| 40 int minutes, | 39 int minutes, |
| 41 int seconds, | 40 int seconds, |
| 42 String expectedFormatted) { | 41 String expectedFormatted) { |
| 43 TimeZone utc = new TimeZone.utc(); | |
| 44 Date date; | 42 Date date; |
| 45 String formatted; | 43 String formatted; |
| 46 date = new Date.withTimeZone( | 44 date = new Date(year, month, day, hours, minutes, seconds, 0, isUtc: true); |
| 47 year, month, day, hours, minutes, seconds, 0, utc); | |
| 48 formatted = _HttpUtils.formatDate(date); | 45 formatted = _HttpUtils.formatDate(date); |
| 49 Expect.equals(expectedFormatted, formatted); | 46 Expect.equals(expectedFormatted, formatted); |
| 50 Expect.equals(date, _HttpUtils.parseDate(formatted)); | 47 Expect.equals(date, _HttpUtils.parseDate(formatted)); |
| 51 } | 48 } |
| 52 | 49 |
| 53 test(1999, Date.JUN, 11, 18, 46, 53, "Fri, 11 Jun 1999 18:46:53 GMT"); | 50 test(1999, Date.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"); | 51 test(1970, Date.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"); | 52 test(2012, Date.MAR, 5, 23, 59, 59, "Mon, 5 Mar 2012 23:59:59 GMT"); |
| 56 } | 53 } |
| 57 | 54 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 84 Expect.throws(() { | 81 Expect.throws(() { |
| 85 _HttpUtils.parseDate("$valid "); | 82 _HttpUtils.parseDate("$valid "); |
| 86 }); | 83 }); |
| 87 } | 84 } |
| 88 | 85 |
| 89 void main() { | 86 void main() { |
| 90 testParseHttpDate(); | 87 testParseHttpDate(); |
| 91 testFormatParseHttpDate(); | 88 testFormatParseHttpDate(); |
| 92 testParseHttpDateFailures(); | 89 testParseHttpDateFailures(); |
| 93 } | 90 } |
| OLD | NEW |