Index: packages/intl/test/date_time_loose_parsing_test.dart |
diff --git a/packages/intl/test/date_time_loose_parsing_test.dart b/packages/intl/test/date_time_loose_parsing_test.dart |
index 6b374709ce35d8a918d1343a52da451b15210dff..aa4fdf78db083b8ec8af07e16eee5538fc91fe3d 100644 |
--- a/packages/intl/test/date_time_loose_parsing_test.dart |
+++ b/packages/intl/test/date_time_loose_parsing_test.dart |
@@ -3,12 +3,15 @@ |
// 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. |
+/// mixed-case input and are able to skip missing delimiters. Such valid input |
+/// is only tested in basic US locale, it's hard to define for others. |
+/// Inputs which should fail because they're missing data (currently only the |
+/// year) are tested in more locales. |
library date_time_loose_test; |
+import 'package:intl/date_symbol_data_local.dart'; |
import 'package:intl/intl.dart'; |
-import 'package:unittest/unittest.dart'; |
+import 'package:test/test.dart'; |
main() { |
var format; |
@@ -34,6 +37,7 @@ main() { |
check("september 3, 2014"); |
check("sEPTembER 3, 2014"); |
check("seP 3, 2014"); |
+ check("Sep 3,2014"); |
}); |
test("Loose parsing yMMMd that parses strict", () { |
@@ -45,12 +49,57 @@ main() { |
check("09 3 2014"); |
check("09 00003 2014"); |
check("09/ 03/2014"); |
- expect(() => format.parseLoose("09 / 03 / 2014"), |
- throwsA(new isInstanceOf<FormatException>())); |
+ check("09 / 03 / 2014"); |
}); |
test("Loose parsing yMd that parses strict", () { |
expect(format.parseLoose("09/03/2014"), date); |
expect(format.parseLoose("09/3/2014"), date); |
}); |
+ |
+ test("Loose parsing should handle standalone month format", () { |
+ // This checks that LL actually sets the month. |
+ // The appended whitespace and extra d pattern are present to trigger the |
+ // loose parsing code path. |
+ expect(new DateFormat('LL/d', 'en_US').parseLoose("05/ 2").month, 5); |
+ }); |
+ |
+ group("Loose parsing with year formats", () { |
+ test("should fail when year is omitted (en_US)", () { |
+ expect(() => new DateFormat('yyyy-MM-dd').parseLoose("1/11"), |
+ throwsFormatException); |
+ }); |
+ |
+ test("should fail when year is omitted (ja)", () { |
+ initializeDateFormatting('ja', null); |
+ expect(() => new DateFormat.yMMMd("ja").parseLoose('12月12日'), |
+ throwsFormatException); |
+ expect(() => new DateFormat.yMd("ja").parseLoose('12月12日'), |
+ throwsFormatException); |
+ expect(() => new DateFormat.yMEd("ja").parseLoose('12月12日'), |
+ throwsFormatException); |
+ expect(() => new DateFormat.yMMMEd("ja").parseLoose('12月12日'), |
+ throwsFormatException); |
+ expect(() => new DateFormat.yMMMMd("ja").parseLoose('12月12日'), |
+ throwsFormatException); |
+ expect(() => new DateFormat.yMMMMEEEEd("ja").parseLoose('12月12日'), |
+ throwsFormatException); |
+ }); |
+ |
+ test("should fail when year is omitted (hu)", () { |
+ initializeDateFormatting('hu', null); |
+ expect(() => new DateFormat.yMMMd("hu").parseLoose('3. 17.'), |
+ throwsFormatException); |
+ expect(() => new DateFormat.yMd("hu").parseLoose('3. 17.'), |
+ throwsFormatException); |
+ expect(() => new DateFormat.yMEd("hu").parseLoose('3. 17.'), |
+ throwsFormatException); |
+ expect(() => new DateFormat.yMMMEd("hu").parseLoose('3. 17.'), |
+ throwsFormatException); |
+ expect(() => new DateFormat.yMMMMd("hu").parseLoose('3. 17.'), |
+ throwsFormatException); |
+ expect(() => new DateFormat.yMMMMEEEEd("hu").parseLoose('3. 17.'), |
+ throwsFormatException); |
+ }); |
+ }); |
} |