| 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 #import("dart:math"); | 5 #import("dart:math"); |
| 6 | 6 |
| 7 #source("../../../runtime/bin/input_stream.dart"); | 7 #source("../../../runtime/bin/input_stream.dart"); |
| 8 #source("../../../runtime/bin/output_stream.dart"); | 8 #source("../../../runtime/bin/output_stream.dart"); |
| 9 #source("../../../runtime/bin/chunked_stream.dart"); | 9 #source("../../../runtime/bin/chunked_stream.dart"); |
| 10 #source("../../../runtime/bin/string_stream.dart"); | 10 #source("../../../runtime/bin/string_stream.dart"); |
| 11 #source("../../../runtime/bin/stream_util.dart"); | 11 #source("../../../runtime/bin/stream_util.dart"); |
| 12 #source("../../../runtime/bin/http.dart"); | 12 #source("../../../runtime/bin/http.dart"); |
| 13 #source("../../../runtime/bin/http_impl.dart"); | 13 #source("../../../runtime/bin/http_impl.dart"); |
| 14 #source("../../../runtime/bin/http_parser.dart"); | 14 #source("../../../runtime/bin/http_parser.dart"); |
| 15 #source("../../../runtime/bin/http_utils.dart"); | 15 #source("../../../runtime/bin/http_utils.dart"); |
| 16 | 16 |
| 17 void testParseHttpDate() { | 17 void testParseHttpDate() { |
| 18 Date date; | 18 Date date; |
| 19 date = new Date(1999, Date.JUN, 11, 18, 46, 53, 0, isUtc: true); | 19 date = new Date.utc(1999, Date.JUN, 11, 18, 46, 53, 0); |
| 20 Expect.equals(date, _HttpUtils.parseDate("Fri, 11 Jun 1999 18:46:53 GMT")); | 20 Expect.equals(date, _HttpUtils.parseDate("Fri, 11 Jun 1999 18:46:53 GMT")); |
| 21 Expect.equals(date, _HttpUtils.parseDate("Friday, 11-Jun-1999 18:46:53 GMT")); | 21 Expect.equals(date, _HttpUtils.parseDate("Friday, 11-Jun-1999 18:46:53 GMT")); |
| 22 Expect.equals(date, _HttpUtils.parseDate("Fri Jun 11 18:46:53 1999")); | 22 Expect.equals(date, _HttpUtils.parseDate("Fri Jun 11 18:46:53 1999")); |
| 23 | 23 |
| 24 date = new Date(1970, Date.JAN, 1, 0, 0, 0, 0, isUtc: true); | 24 date = new Date.utc(1970, Date.JAN, 1, 0, 0, 0, 0); |
| 25 Expect.equals(date, _HttpUtils.parseDate("Thu, 1 Jan 1970 00:00:00 GMT")); | 25 Expect.equals(date, _HttpUtils.parseDate("Thu, 1 Jan 1970 00:00:00 GMT")); |
| 26 Expect.equals(date, | 26 Expect.equals(date, |
| 27 _HttpUtils.parseDate("Thursday, 1-Jan-1970 00:00:00 GMT")); | 27 _HttpUtils.parseDate("Thursday, 1-Jan-1970 00:00:00 GMT")); |
| 28 Expect.equals(date, _HttpUtils.parseDate("Thu Jan 1 00:00:00 1970")); | 28 Expect.equals(date, _HttpUtils.parseDate("Thu Jan 1 00:00:00 1970")); |
| 29 | 29 |
| 30 date = new Date(2012, Date.MAR, 5, 23, 59, 59, 0, isUtc: true); | 30 date = new Date.utc(2012, Date.MAR, 5, 23, 59, 59, 0); |
| 31 Expect.equals(date, _HttpUtils.parseDate("Mon, 5 Mar 2012 23:59:59 GMT")); | 31 Expect.equals(date, _HttpUtils.parseDate("Mon, 5 Mar 2012 23:59:59 GMT")); |
| 32 Expect.equals(date, _HttpUtils.parseDate("Monday, 5-Mar-2012 23:59:59 GMT")); | 32 Expect.equals(date, _HttpUtils.parseDate("Monday, 5-Mar-2012 23:59:59 GMT")); |
| 33 Expect.equals(date, _HttpUtils.parseDate("Mon Mar 5 23:59:59 2012")); | 33 Expect.equals(date, _HttpUtils.parseDate("Mon Mar 5 23:59:59 2012")); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void testFormatParseHttpDate() { | 36 void testFormatParseHttpDate() { |
| 37 test(int year, | 37 test(int year, |
| 38 int month, | 38 int month, |
| 39 int day, | 39 int day, |
| 40 int hours, | 40 int hours, |
| 41 int minutes, | 41 int minutes, |
| 42 int seconds, | 42 int seconds, |
| 43 String expectedFormatted) { | 43 String expectedFormatted) { |
| 44 Date date; | 44 Date date; |
| 45 String formatted; | 45 String formatted; |
| 46 date = new Date(year, month, day, hours, minutes, seconds, 0, isUtc: true); | 46 date = new Date.utc(year, month, day, hours, minutes, seconds, 0); |
| 47 formatted = _HttpUtils.formatDate(date); | 47 formatted = _HttpUtils.formatDate(date); |
| 48 Expect.equals(expectedFormatted, formatted); | 48 Expect.equals(expectedFormatted, formatted); |
| 49 Expect.equals(date, _HttpUtils.parseDate(formatted)); | 49 Expect.equals(date, _HttpUtils.parseDate(formatted)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 test(1999, Date.JUN, 11, 18, 46, 53, "Fri, 11 Jun 1999 18:46:53 GMT"); | 52 test(1999, Date.JUN, 11, 18, 46, 53, "Fri, 11 Jun 1999 18:46:53 GMT"); |
| 53 test(1970, Date.JAN, 1, 0, 0, 0, "Thu, 1 Jan 1970 00:00:00 GMT"); | 53 test(1970, Date.JAN, 1, 0, 0, 0, "Thu, 1 Jan 1970 00:00:00 GMT"); |
| 54 test(2012, Date.MAR, 5, 23, 59, 59, "Mon, 5 Mar 2012 23:59:59 GMT"); | 54 test(2012, Date.MAR, 5, 23, 59, 59, "Mon, 5 Mar 2012 23:59:59 GMT"); |
| 55 } | 55 } |
| 56 | 56 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 void testParseHttpCookieDate() { | 88 void testParseHttpCookieDate() { |
| 89 Expect.throws(() => _HttpUtils.parseCookieDate("")); | 89 Expect.throws(() => _HttpUtils.parseCookieDate("")); |
| 90 | 90 |
| 91 test(int year, | 91 test(int year, |
| 92 int month, | 92 int month, |
| 93 int day, | 93 int day, |
| 94 int hours, | 94 int hours, |
| 95 int minutes, | 95 int minutes, |
| 96 int seconds, | 96 int seconds, |
| 97 String formatted) { | 97 String formatted) { |
| 98 Date date = new Date( | 98 Date date = new Date.utc(year, month, day, hours, minutes, seconds, 0); |
| 99 year, month, day, hours, minutes, seconds, 0, isUtc: true); | |
| 100 Expect.equals(date, _HttpUtils.parseCookieDate(formatted)); | 99 Expect.equals(date, _HttpUtils.parseCookieDate(formatted)); |
| 101 } | 100 } |
| 102 | 101 |
| 103 test(2012, Date.JUN, 19, 14, 15, 01, "tue, 19-jun-12 14:15:01 gmt"); | 102 test(2012, Date.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"); | 103 test(2021, Date.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"); | 104 test(2021, Date.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"); | 105 test(2013, Date.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"); | 106 test(1970, Date.JAN, 01, 00, 00, 01, "Thu, 01-Jan-1970 00:00:01 GMT"); |
| 108 } | 107 } |
| 109 | 108 |
| 110 void main() { | 109 void main() { |
| 111 testParseHttpDate(); | 110 testParseHttpDate(); |
| 112 testFormatParseHttpDate(); | 111 testFormatParseHttpDate(); |
| 113 testParseHttpDateFailures(); | 112 testParseHttpDateFailures(); |
| 114 testParseHttpCookieDate(); | 113 testParseHttpCookieDate(); |
| 115 } | 114 } |
| OLD | NEW |