| Index: pkg/shelf/test/http_date_test.dart
|
| diff --git a/pkg/shelf/test/http_date_test.dart b/pkg/shelf/test/http_date_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4af874f9014ec2d0271875463809284705b2ca47
|
| --- /dev/null
|
| +++ b/pkg/shelf/test/http_date_test.dart
|
| @@ -0,0 +1,315 @@
|
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +library shelf.http_date_test;
|
| +
|
| +import 'package:shelf/src/util.dart';
|
| +import 'package:unittest/unittest.dart';
|
| +
|
| +void main() {
|
| + group("parse", () {
|
| + group("RFC 1123", () {
|
| + test("parses the example date", () {
|
| + var date = parseHttpDate("Sun, 06 Nov 1994 08:49:37 GMT");
|
| + expect(date.day, equals(6));
|
| + expect(date.month, equals(DateTime.NOVEMBER));
|
| + expect(date.year, equals(1994));
|
| + expect(date.hour, equals(8));
|
| + expect(date.minute, equals(49));
|
| + expect(date.second, equals(37));
|
| + expect(date.timeZoneName, equals("UTC"));
|
| + });
|
| +
|
| + test("whitespace is required", () {
|
| + expect(() => parseHttpDate("Sun,06 Nov 1994 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 06Nov 1994 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 06 Nov1994 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 06 Nov 199408:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 06 Nov 1994 08:49:37GMT"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("exactly one space is required", () {
|
| + expect(() => parseHttpDate("Sun, 06 Nov 1994 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 06 Nov 1994 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 06 Nov 1994 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 06 Nov 1994 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 06 Nov 1994 08:49:37 GMT"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("requires precise number lengths", () {
|
| + expect(() => parseHttpDate("Sun, 6 Nov 1994 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 06 Nov 94 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 06 Nov 1994 8:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 06 Nov 1994 08:9:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 06 Nov 1994 08:49:7 GMT"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("requires reasonable numbers", () {
|
| + expect(() => parseHttpDate("Sun, 00 Nov 1994 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 31 Nov 1994 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 32 Aug 1994 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 06 Nov 1994 24:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 06 Nov 1994 08:60:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun, 06 Nov 1994 08:49:60 GMT"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("only allows short weekday names", () {
|
| + expect(() => parseHttpDate("Sunday, 6 Nov 1994 08:49:37 GMT"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("only allows short month names", () {
|
| + expect(() => parseHttpDate("Sun, 6 November 1994 08:49:37 GMT"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("only allows GMT", () {
|
| + expect(() => parseHttpDate("Sun, 6 Nov 1994 08:49:37 PST"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("disallows trailing whitespace", () {
|
| + expect(() => parseHttpDate("Sun, 6 Nov 1994 08:49:37 GMT "),
|
| + throwsFormatException);
|
| + });
|
| + });
|
| +
|
| + group("RFC 850", () {
|
| + test("parses the example date", () {
|
| + var date = parseHttpDate("Sunday, 06-Nov-94 08:49:37 GMT");
|
| + expect(date.day, equals(6));
|
| + expect(date.month, equals(DateTime.NOVEMBER));
|
| + expect(date.year, equals(1994));
|
| + expect(date.hour, equals(8));
|
| + expect(date.minute, equals(49));
|
| + expect(date.second, equals(37));
|
| + expect(date.timeZoneName, equals("UTC"));
|
| + });
|
| +
|
| + test("whitespace is required", () {
|
| + expect(() => parseHttpDate("Sunday,06-Nov-94 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sunday, 06-Nov-9408:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sunday, 06-Nov-94 08:49:37GMT"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("exactly one space is required", () {
|
| + expect(() => parseHttpDate("Sunday, 06-Nov-94 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sunday, 06-Nov-94 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sunday, 06-Nov-94 08:49:37 GMT"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("requires precise number lengths", () {
|
| + expect(() => parseHttpDate("Sunday, 6-Nov-94 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sunday, 06-Nov-1994 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sunday, 06-Nov-94 8:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sunday, 06-Nov-94 08:9:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sunday, 06-Nov-94 08:49:7 GMT"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("requires reasonable numbers", () {
|
| + expect(() => parseHttpDate("Sunday, 00-Nov-94 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sunday, 31-Nov-94 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sunday, 32-Aug-94 08:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sunday, 06-Nov-94 24:49:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sunday, 06-Nov-94 08:60:37 GMT"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sunday, 06-Nov-94 08:49:60 GMT"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("only allows long weekday names", () {
|
| + expect(() => parseHttpDate("Sun, 6-Nov-94 08:49:37 GMT"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("only allows short month names", () {
|
| + expect(() => parseHttpDate("Sunday, 6-November-94 08:49:37 GMT"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("only allows GMT", () {
|
| + expect(() => parseHttpDate("Sunday, 6-Nov-94 08:49:37 PST"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("disallows trailing whitespace", () {
|
| + expect(() => parseHttpDate("Sunday, 6-Nov-94 08:49:37 GMT "),
|
| + throwsFormatException);
|
| + });
|
| + });
|
| +
|
| + group("asctime()", () {
|
| + test("parses the example date", () {
|
| + var date = parseHttpDate("Sun Nov 6 08:49:37 1994");
|
| + expect(date.day, equals(6));
|
| + expect(date.month, equals(DateTime.NOVEMBER));
|
| + expect(date.year, equals(1994));
|
| + expect(date.hour, equals(8));
|
| + expect(date.minute, equals(49));
|
| + expect(date.second, equals(37));
|
| + expect(date.timeZoneName, equals("UTC"));
|
| + });
|
| +
|
| + test("parses a date with a two-digit day", () {
|
| + var date = parseHttpDate("Sun Nov 16 08:49:37 1994");
|
| + expect(date.day, equals(16));
|
| + expect(date.month, equals(DateTime.NOVEMBER));
|
| + expect(date.year, equals(1994));
|
| + expect(date.hour, equals(8));
|
| + expect(date.minute, equals(49));
|
| + expect(date.second, equals(37));
|
| + expect(date.timeZoneName, equals("UTC"));
|
| + });
|
| +
|
| + test("whitespace is required", () {
|
| + expect(() => parseHttpDate("SunNov 6 08:49:37 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Nov6 08:49:37 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Nov 608:49:37 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Nov 6 08:49:371994"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("the right amount of whitespace is required", () {
|
| + expect(() => parseHttpDate("Sun Nov 6 08:49:37 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Nov 6 08:49:37 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Nov 6 08:49:37 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Nov 6 08:49:37 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Nov 6 08:49:37 1994"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("requires precise number lengths", () {
|
| + expect(() => parseHttpDate("Sun Nov 016 08:49:37 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Nov 6 8:49:37 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Nov 6 08:9:37 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Nov 6 08:49:7 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Nov 6 08:49:37 94"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("requires reasonable numbers", () {
|
| + expect(() => parseHttpDate("Sun Nov 0 08:49:37 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Nov 31 08:49:37 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Aug 32 08:49:37 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Nov 6 24:49:37 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Nov 6 08:60:37 1994"),
|
| + throwsFormatException);
|
| +
|
| + expect(() => parseHttpDate("Sun Nov 6 08:49:60 1994"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("only allows short weekday names", () {
|
| + expect(() => parseHttpDate("Sunday Nov 0 08:49:37 1994"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("only allows short month names", () {
|
| + expect(() => parseHttpDate("Sun November 0 08:49:37 1994"),
|
| + throwsFormatException);
|
| + });
|
| +
|
| + test("disallows trailing whitespace", () {
|
| + expect(() => parseHttpDate("Sun November 0 08:49:37 1994 "),
|
| + throwsFormatException);
|
| + });
|
| + });
|
| + });
|
| +}
|
|
|