Add an example
diff --git a/example/example.dart b/example/example.dart new file mode 100644 index 0000000..9230b6a --- /dev/null +++ b/example/example.dart
@@ -0,0 +1,16 @@ +// Copyright (c) 2020, 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. + +import 'package:http_parser/http_parser.dart'; + +void main() { + final date = DateTime.utc(2014, 9, 9, 9, 9, 9); + print(date); // 2014-09-09 09:09:09.000Z + + final httpDateFormatted = formatHttpDate(date); + print(httpDateFormatted); // Tue, 09 Sep 2014 09:09:09 GMT + + final nowParsed = parseHttpDate(httpDateFormatted); + print(nowParsed); // 2014-09-09 09:09:09.000Z +}
diff --git a/test/example_test.dart b/test/example_test.dart new file mode 100644 index 0000000..ef61060 --- /dev/null +++ b/test/example_test.dart
@@ -0,0 +1,19 @@ +import 'dart:io'; + +import 'package:test/test.dart'; + +void main() { + test('validate example', () { + final result = Process.runSync( + Platform.executable, + ['example/example.dart'], + ); + + expect(result.exitCode, 0); + expect(result.stdout, ''' +2014-09-09 09:09:09.000Z +Tue, 09 Sep 2014 09:09:09 GMT +2014-09-09 09:09:09.000Z +'''); + }, testOn: 'vm'); +}