OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /// Tests for the loose option when parsing dates and times, which accept |
| 6 /// mixed-case input and are able to skip missing delimiters. This is only |
| 7 /// tested in basic US locale, it's hard to define for others. |
| 8 library date_time_loose_test; |
| 9 |
| 10 import 'package:intl/intl.dart'; |
| 11 import 'package:unittest/unittest.dart'; |
| 12 |
| 13 main() { |
| 14 var format; |
| 15 |
| 16 var date = new DateTime(2014, 9, 3); |
| 17 |
| 18 check(String s) { |
| 19 expect(() => format.parse(s), throwsFormatException); |
| 20 expect(format.parseLoose(s), date); |
| 21 } |
| 22 |
| 23 test("Loose parsing yMMMd", () { |
| 24 // Note: We can't handle e.g. Sept, we don't have those abbreviations |
| 25 // in our data. |
| 26 // Also doesn't handle "sep3,2014", or "sep 3.2014" |
| 27 format = new DateFormat.yMMMd("en_US"); |
| 28 check("Sep 3 2014"); |
| 29 check("sep 3 2014"); |
| 30 check("sep 3 2014"); |
| 31 check("sep 3 2014"); |
| 32 check("sep 3 2014"); |
| 33 check("sep3 2014"); |
| 34 check("september 3, 2014"); |
| 35 check("sEPTembER 3, 2014"); |
| 36 check("seP 3, 2014"); |
| 37 }); |
| 38 |
| 39 test("Loose parsing yMMMd that parses strict", () { |
| 40 expect(format.parseLoose("Sep 3, 2014"), date); |
| 41 }); |
| 42 |
| 43 test("Loose parsing yMd", () { |
| 44 format = new DateFormat.yMd("en_US"); |
| 45 check("09 3 2014"); |
| 46 check("09 00003 2014"); |
| 47 check("09/ 03/2014"); |
| 48 expect(() => format.parseLoose("09 / 03 / 2014"), |
| 49 throwsA(new isInstanceOf<FormatException>())); |
| 50 }); |
| 51 |
| 52 test("Loose parsing yMd that parses strict", () { |
| 53 expect(format.parseLoose("09/03/2014"), date); |
| 54 expect(format.parseLoose("09/3/2014"), date); |
| 55 }); |
| 56 } |
OLD | NEW |