Chromium Code Reviews| 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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
|
Anders Johnsen
2013/06/12 11:08:45
Make test into an import 'dart:io' test?
Søren Gjesse
2013/06/12 12:16:00
Split the test into two:
http_date_test.dart
| |
| 6 import "dart:async"; | 6 import "dart:async"; |
| 7 import "dart:math"; | 7 import "dart:math"; |
| 8 | 8 |
| 9 part '../../../sdk/lib/io/common.dart'; | 9 part '../../../sdk/lib/io/common.dart'; |
| 10 part "../../../sdk/lib/io/io_sink.dart"; | 10 part "../../../sdk/lib/io/io_sink.dart"; |
| 11 part "../../../sdk/lib/io/http.dart"; | 11 part "../../../sdk/lib/io/http.dart"; |
| 12 part "../../../sdk/lib/io/http_impl.dart"; | 12 part "../../../sdk/lib/io/http_impl.dart"; |
| 13 part "../../../sdk/lib/io/http_parser.dart"; | 13 part "../../../sdk/lib/io/http_parser.dart"; |
| 14 part "../../../sdk/lib/io/http_utils.dart"; | 14 part "../../../sdk/lib/io/http_utils.dart"; |
| 15 part "../../../sdk/lib/io/socket.dart"; | 15 part "../../../sdk/lib/io/socket.dart"; |
| 16 | 16 |
| 17 void testParseHttpDate() { | 17 void testParseHttpDate() { |
| 18 DateTime date; | 18 DateTime date; |
| 19 date = new DateTime.utc(1999, DateTime.JUNE, 11, 18, 46, 53, 0); | 19 date = new DateTime.utc(1999, DateTime.JUNE, 11, 18, 46, 53, 0); |
| 20 Expect.equals(date, _HttpUtils.parseDate("Fri, 11 Jun 1999 18:46:53 GMT")); | 20 Expect.equals(date, HttpDate.parse("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, HttpDate.parse("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, HttpDate.parse("Fri Jun 11 18:46:53 1999")); |
| 23 | 23 |
| 24 date = new DateTime.utc(1970, DateTime.JANUARY, 1, 0, 0, 0, 0); | 24 date = new DateTime.utc(1970, DateTime.JANUARY, 1, 0, 0, 0, 0); |
| 25 Expect.equals(date, _HttpUtils.parseDate("Thu, 1 Jan 1970 00:00:00 GMT")); | 25 Expect.equals(date, HttpDate.parse("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 HttpDate.parse("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, HttpDate.parse("Thu Jan 1 00:00:00 1970")); |
| 29 | 29 |
| 30 date = new DateTime.utc(2012, DateTime.MARCH, 5, 23, 59, 59, 0); | 30 date = new DateTime.utc(2012, DateTime.MARCH, 5, 23, 59, 59, 0); |
| 31 Expect.equals(date, _HttpUtils.parseDate("Mon, 5 Mar 2012 23:59:59 GMT")); | 31 Expect.equals(date, HttpDate.parse("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, HttpDate.parse("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, HttpDate.parse("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 DateTime date; | 44 DateTime date; |
| 45 String formatted; | 45 String formatted; |
| 46 date = new DateTime.utc(year, month, day, hours, minutes, seconds, 0); | 46 date = new DateTime.utc(year, month, day, hours, minutes, seconds, 0); |
| 47 formatted = _HttpUtils.formatDate(date); | 47 formatted = HttpDate.format(date); |
| 48 Expect.equals(expectedFormatted, formatted); | 48 Expect.equals(expectedFormatted, formatted); |
| 49 Expect.equals(date, _HttpUtils.parseDate(formatted)); | 49 Expect.equals(date, HttpDate.parse(formatted)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 test(1999, DateTime.JUNE, 11, 18, 46, 53, "Fri, 11 Jun 1999 18:46:53 GMT"); | 52 test(1999, DateTime.JUNE, 11, 18, 46, 53, "Fri, 11 Jun 1999 18:46:53 GMT"); |
| 53 test(1970, DateTime.JANUARY, 1, 0, 0, 0, "Thu, 1 Jan 1970 00:00:00 GMT"); | 53 test(1970, DateTime.JANUARY, 1, 0, 0, 0, "Thu, 1 Jan 1970 00:00:00 GMT"); |
| 54 test(2012, DateTime.MARCH, 5, 23, 59, 59, "Mon, 5 Mar 2012 23:59:59 GMT"); | 54 test(2012, DateTime.MARCH, 5, 23, 59, 59, "Mon, 5 Mar 2012 23:59:59 GMT"); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void testParseHttpDateFailures() { | 57 void testParseHttpDateFailures() { |
| 58 Expect.throws(() { | 58 Expect.throws(() { |
| 59 _HttpUtils.parseDate(""); | 59 HttpDate.parse(""); |
| 60 }); | 60 }); |
| 61 String valid = "Mon, 5 Mar 2012 23:59:59 GMT"; | 61 String valid = "Mon, 5 Mar 2012 23:59:59 GMT"; |
| 62 for (int i = 1; i < valid.length - 1; i++) { | 62 for (int i = 1; i < valid.length - 1; i++) { |
| 63 String tmp = valid.substring(0, i); | 63 String tmp = valid.substring(0, i); |
| 64 Expect.throws(() { | 64 Expect.throws(() { |
| 65 _HttpUtils.parseDate(tmp); | 65 HttpDate.parse(tmp); |
| 66 }); | 66 }); |
| 67 Expect.throws(() { | 67 Expect.throws(() { |
| 68 _HttpUtils.parseDate(" $tmp"); | 68 HttpDate.parse(" $tmp"); |
| 69 }); | 69 }); |
| 70 Expect.throws(() { | 70 Expect.throws(() { |
| 71 _HttpUtils.parseDate(" $tmp "); | 71 HttpDate.parse(" $tmp "); |
| 72 }); | 72 }); |
| 73 Expect.throws(() { | 73 Expect.throws(() { |
| 74 _HttpUtils.parseDate("$tmp "); | 74 HttpDate.parse("$tmp "); |
| 75 }); | 75 }); |
| 76 } | 76 } |
| 77 Expect.throws(() { | 77 Expect.throws(() { |
| 78 _HttpUtils.parseDate(" $valid"); | 78 HttpDate.parse(" $valid"); |
| 79 }); | 79 }); |
| 80 Expect.throws(() { | 80 Expect.throws(() { |
| 81 _HttpUtils.parseDate(" $valid "); | 81 HttpDate.parse(" $valid "); |
| 82 }); | 82 }); |
| 83 Expect.throws(() { | 83 Expect.throws(() { |
| 84 _HttpUtils.parseDate("$valid "); | 84 HttpDate.parse("$valid "); |
| 85 }); | 85 }); |
| 86 } | 86 } |
| 87 | 87 |
| 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, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 105 test(2013, DateTime.JANUARY, 15, 21, 47, 38, "Tue, 15-Jan-2013 21:47:38 GMT"); | 105 test(2013, DateTime.JANUARY, 15, 21, 47, 38, "Tue, 15-Jan-2013 21:47:38 GMT"); |
| 106 test(1970, DateTime.JANUARY, 01, 00, 00, 01, "Thu, 01-Jan-1970 00:00:01 GMT"); | 106 test(1970, DateTime.JANUARY, 01, 00, 00, 01, "Thu, 01-Jan-1970 00:00:01 GMT"); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void main() { | 109 void main() { |
| 110 testParseHttpDate(); | 110 testParseHttpDate(); |
| 111 testFormatParseHttpDate(); | 111 testFormatParseHttpDate(); |
| 112 testParseHttpDateFailures(); | 112 testParseHttpDateFailures(); |
| 113 testParseHttpCookieDate(); | 113 testParseHttpCookieDate(); |
| 114 } | 114 } |
| OLD | NEW |