1 extern crate datetime;
2 pub use datetime::{YearMonth, Year};
3 
4 mod months {
5     use super::*;
6     use datetime::Month::*;
7 
8     #[test]
range_full()9     fn range_full() {
10         let year = Year(2013);
11         let months: Vec<_> = year.months(..).collect();
12         assert_eq!(months, vec![
13             year.month(January),
14             year.month(February),
15             year.month(March),
16             year.month(April),
17             year.month(May),
18             year.month(June),
19             year.month(July),
20             year.month(August),
21             year.month(September),
22             year.month(October),
23             year.month(November),
24             year.month(December),
25         ]);
26     }
27 
28     #[test]
range_from()29     fn range_from() {
30         let year = Year(2013);
31         let months: Vec<_> = year.months(July..).collect();
32         assert_eq!(months, vec![
33             year.month(July),
34             year.month(August),
35             year.month(September),
36             year.month(October),
37             year.month(November),
38             year.month(December),
39         ]);
40     }
41 
42     #[test]
range_to()43     fn range_to() {
44         let year = Year(2013);
45         let months: Vec<_> = year.months(..July).collect();
46         assert_eq!(months, vec![
47             year.month(January),
48             year.month(February),
49             year.month(March),
50             year.month(April),
51             year.month(May),
52             year.month(June),
53         ]);
54     }
55 
56     #[test]
range()57     fn range() {
58         let year = Year(2013);
59         let months: Vec<_> = year.months(April..July).collect();
60         assert_eq!(months, vec![
61             year.month(April),
62             year.month(May),
63             year.month(June),
64         ]);
65     }
66 
67     #[test]
range_empty()68     fn range_empty() {
69         let year = Year(2013);
70         let months: Vec<_> = year.months(August..August).collect();
71         assert!(months.is_empty());
72     }
73 
74     #[test]
range_singular()75     fn range_singular() {
76         let year = Year(2013);
77         let months = year.month(April);
78         assert_eq!(months, year.month(April));
79     }
80 }
81 
82 mod days {
83     use super::*;
84     use datetime::LocalDate;
85     use datetime::Month::*;
86 
87     #[test]
range_full()88     fn range_full() {
89         let year = Year(2013).month(February);
90         let days: Vec<_> = year.days(..).collect();
91         let results: Vec<_> = (1..29).map(|d| LocalDate::ymd(2013, February, d).unwrap()).collect();
92         assert_eq!(days, results);
93     }
94 
95     #[test]
range_full_leap_year()96     fn range_full_leap_year() {
97         let year = Year(2000).month(February);
98         let days: Vec<_> = year.days(..).collect();
99         let results: Vec<_> = (1..30).map(|d| LocalDate::ymd(2000, February, d).unwrap()).collect();
100         assert_eq!(days, results);
101     }
102 
103     #[test]
range()104     fn range() {
105         let year = Year(2008).month(March);
106         let days: Vec<_> = year.days(10..20).collect();
107         let results: Vec<_> = (10..20).map(|d| LocalDate::ymd(2008, March, d).unwrap()).collect();
108         assert_eq!(days, results);
109     }
110 
111     #[test]
just_for_one_day()112     fn just_for_one_day() {
113         let day = Year(1066).month(October).day(14);
114         assert_eq!(day, LocalDate::ymd(1066, October, 14));
115     }
116 }
117 
118 #[test]
entire_year()119 fn entire_year() {
120     let count = Year(1999).months(..)
121                           .flat_map(|m| m.days(..))
122                           .count();
123 
124     assert_eq!(count, 365);
125 }
126 
127 #[test]
entire_leap_year()128 fn entire_leap_year() {
129     let count = Year(2000).months(..)
130                           .flat_map(|m| m.days(..))
131                           .count();
132 
133     assert_eq!(count, 366);
134 }
135