OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library http_parser.http_date_test; | 5 library http_parser.http_date_test; |
6 | 6 |
7 import 'package:http_parser/http_parser.dart'; | 7 import 'package:http_parser/http_parser.dart'; |
8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
9 | 9 |
10 void main() { | 10 void main() { |
| 11 group('format', () { |
| 12 test('many values with 9', () { |
| 13 var date = new DateTime.utc(2014, 9, 9, 9, 9, 9); |
| 14 var formatted = formatHttpDate(date); |
| 15 |
| 16 expect(formatted, 'Tue, 09 Sep 2014 09:09:09 GMT'); |
| 17 var parsed = parseHttpDate(formatted); |
| 18 |
| 19 expect(parsed, date); |
| 20 }); |
| 21 |
| 22 test('end of year', () { |
| 23 var date = new DateTime.utc(1999, 12, 31, 23, 59, 59); |
| 24 var formatted = formatHttpDate(date); |
| 25 |
| 26 expect(formatted, 'Fri, 31 Dec 1999 23:59:59 GMT'); |
| 27 var parsed = parseHttpDate(formatted); |
| 28 |
| 29 expect(parsed, date); |
| 30 }); |
| 31 |
| 32 test('start of year', () { |
| 33 var date = new DateTime.utc(2000, 1, 1, 0, 0, 0); |
| 34 var formatted = formatHttpDate(date); |
| 35 |
| 36 expect(formatted, 'Sat, 01 Jan 2000 00:00:00 GMT'); |
| 37 var parsed = parseHttpDate(formatted); |
| 38 |
| 39 expect(parsed, date); |
| 40 }); |
| 41 }); |
| 42 |
11 group("parse", () { | 43 group("parse", () { |
12 group("RFC 1123", () { | 44 group("RFC 1123", () { |
13 test("parses the example date", () { | 45 test("parses the example date", () { |
14 var date = parseHttpDate("Sun, 06 Nov 1994 08:49:37 GMT"); | 46 var date = parseHttpDate("Sun, 06 Nov 1994 08:49:37 GMT"); |
15 expect(date.day, equals(6)); | 47 expect(date.day, equals(6)); |
16 expect(date.month, equals(DateTime.NOVEMBER)); | 48 expect(date.month, equals(DateTime.NOVEMBER)); |
17 expect(date.year, equals(1994)); | 49 expect(date.year, equals(1994)); |
18 expect(date.hour, equals(8)); | 50 expect(date.hour, equals(8)); |
19 expect(date.minute, equals(49)); | 51 expect(date.minute, equals(49)); |
20 expect(date.second, equals(37)); | 52 expect(date.second, equals(37)); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 throwsFormatException); | 338 throwsFormatException); |
307 }); | 339 }); |
308 | 340 |
309 test("disallows trailing whitespace", () { | 341 test("disallows trailing whitespace", () { |
310 expect(() => parseHttpDate("Sun November 0 08:49:37 1994 "), | 342 expect(() => parseHttpDate("Sun November 0 08:49:37 1994 "), |
311 throwsFormatException); | 343 throwsFormatException); |
312 }); | 344 }); |
313 }); | 345 }); |
314 }); | 346 }); |
315 } | 347 } |
OLD | NEW |