Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: test/date_time_loose_parsing_test.dart

Issue 932093004: Add loose parsing option for dates, accepting mixed case and missing delimiters (Closed) Base URL: https://github.com/dart-lang/intl.git@master
Patch Set: Fix test that wasn't checking for exception Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/date_time_loose_parsing_test.dart
diff --git a/test/date_time_loose_parsing_test.dart b/test/date_time_loose_parsing_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..11589820c002ef173b5c4c63df9f559d49e9173c
--- /dev/null
+++ b/test/date_time_loose_parsing_test.dart
@@ -0,0 +1,55 @@
+// 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.
+
+/// Tests for the loose option when parsing dates and times, which accept
+/// mixed-case input and are able to skip missing delimiters. This is only
+/// tested in basic US locale, it's hard to define for others.
+library date_time_loose_test;
+
+import 'package:intl/intl.dart';
+import 'package:unittest/unittest.dart';
+
+main() {
+ var format;
+
+ var date = new DateTime(2014, 9, 3);
+
+ check(String s) {
+ expect(() => format.parse(s), throwsFormatException);
+ expect(format.parseLoose(s), date);
+ }
+
+ test("Loose parsing yMMMd", () {
+ // Note: We can't handle e.g. Sept, we don't have those abbreviations
+ // in our data.
+ // Also doesn't handle "sep3,2014", or "sep 3.2014"
+ format = new DateFormat.yMMMd("en_US");
+ check("Sep 3 2014");
+ check("sep 3 2014");
+ check("sep 3 2014");
+ check("sep 3 2014");
+ check("sep 3 2014");
+ check("sep3 2014");
+ check("september 3, 2014");
+ check("sEPTembER 3, 2014");
+ check("seP 3, 2014");
+ });
+
+ test("Loose parsing yMMMd that parses strict", () {
+ expect(format.parseLoose("Sep 3, 2014"), date);
+ });
+
+ test("Loose parsing yMd", () {
+ format = new DateFormat.yMd("en_US");
+ check("09 3 2014");
+ check("09 00003 2014");
+ check("09/ 03/2014");
+ expect(() => format.parseLoose("09 / 03 / 2014"), throwsA(new isInstanceOf<FormatException>()));
+ });
+
+ test("Loose parsing yMd that parses strict", () {
+ expect(format.parseLoose("09/03/2014"), date);
+ expect(format.parseLoose("09/3/2014"), date);
+ });
+}
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698