OLD | NEW |
(Empty) | |
| 1 library date_spec; |
| 2 |
| 3 import '../_specs.dart'; |
| 4 import 'package:intl/intl.dart'; |
| 5 |
| 6 void main() { |
| 7 describe('date', () { |
| 8 var morning = DateTime.parse('2010-09-03T07:05:08.008Z'); //7am |
| 9 var noon = DateTime.parse('2010-09-03T12:05:08.012Z'); //12pm |
| 10 var midnight = DateTime.parse('2010-09-03T12:05:08.123Z'); //12am |
| 11 var earlyDate = DateTime.parse('0001-09-03T05:05:08.000Z'); |
| 12 |
| 13 var date; |
| 14 |
| 15 beforeEach((FormatterMap map, Injector injector) { |
| 16 date = injector.get(map[new Formatter(name: 'date')]); |
| 17 }); |
| 18 |
| 19 it('should ignore falsy inputs', () { |
| 20 expect(date(null)).toBeNull(); |
| 21 expect(date('')).toEqual(''); |
| 22 }); |
| 23 |
| 24 it('should do basic formatter', () { |
| 25 expect(date(noon)).toEqual(date(noon, 'mediumDate')); |
| 26 }); |
| 27 |
| 28 it('should accept various format strings', () { |
| 29 expect(date(morning, "yy-MM-dd HH:mm:ss")). |
| 30 toEqual('10-09-03 07:05:08'); |
| 31 |
| 32 expect(date(morning, "yy-MM-dd HH:mm:ss.sss")). |
| 33 toEqual('10-09-03 07:05:08.008'); |
| 34 }); |
| 35 |
| 36 it('should accept default formats', () { |
| 37 |
| 38 expect(date(noon, "medium")). |
| 39 toEqual('Sep 3, 2010 12:05:08 PM'); |
| 40 |
| 41 expect(date(noon, "short")). |
| 42 toEqual('9/3/10 12:05 PM'); |
| 43 |
| 44 expect(date(noon, "fullDate")). |
| 45 toEqual('Friday, September 3, 2010'); |
| 46 |
| 47 expect(date(noon, "longDate")). |
| 48 toEqual('September 3, 2010'); |
| 49 |
| 50 expect(date(noon, "mediumDate")). |
| 51 toEqual('Sep 3, 2010'); |
| 52 |
| 53 expect(date(noon, "shortDate")). |
| 54 toEqual('9/3/10'); |
| 55 |
| 56 expect(date(noon, "mediumTime")). |
| 57 toEqual('12:05:08 PM'); |
| 58 |
| 59 expect(date(noon, "shortTime")). |
| 60 toEqual('12:05 PM'); |
| 61 }); |
| 62 |
| 63 it('should use cache without any error', () { |
| 64 |
| 65 date(noon, "shortTime"); |
| 66 date(noon, "shortTime"); |
| 67 }); |
| 68 |
| 69 |
| 70 it('should accept various locales', async(() { |
| 71 expect(Intl.withLocale('de', () => date(noon, "medium"))). |
| 72 toEqual('Sep 3, 2010 12:05:08 nachm.'); |
| 73 expect(Intl.withLocale('fr', () => date(noon, "medium"))). |
| 74 toEqual('sept. 3, 2010 12:05:08 PM'); |
| 75 })); |
| 76 }); |
| 77 } |
OLD | NEW |