summaryrefslogtreecommitdiff
path: root/tests/rrule.rs
blob: 4f96320bbe636977159642bc251afeb62ff25abc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
extern crate chrono;
extern crate rust_ical;

use chrono::prelude::*;
use rust_ical::iter::*;
use rust_ical::options::*;
use rust_ical::yearinfo::*;

#[cfg(test)]
mod test {
    use super::*;

    fn ymd_hms(
        year: i32,
        month: u32,
        day: u32,
        hour: u32,
        minute: u32,
        second: u32,
    ) -> DateTime<Utc> {
        Utc.ymd(year, month, day).and_hms(hour, minute, second)
    }

    fn test_recurring(msg: &str, options: &mut ParsedOptions, expected_dates: &Vec<DateTime<Utc>>) {
        let iter_args = IterArgs {
            inc: true,
            before: Utc::now(),
            after: Utc::now(),
            dt: Utc::now(),
            _value: Some(vec![]),
        };
        let mut iter_res = IterResult::new(QueryMethodTypes::ALL, iter_args);
        let res = iter(&mut iter_res, options);

        assert_eq!(
            res.len(),
            expected_dates.len(),
            "Expected number of returned dates to be equal to the expected"
        );

        for (actual, exptected) in res.iter().zip(expected_dates) {
            assert_eq!(actual, exptected, "{}", msg);
        }
    }

    #[test]
    fn int_works() {
        let mut options = ParsedOptions::new(Frequenzy::WEEKLY, 5, &ymd_hms(2012, 1, 1, 10, 30, 0))
            .count(3)
            .byweekday(vec![0, 4])
            .bymonth(vec![6]);
        test_recurring(
            "should work",
            &mut options,
            &vec![
                ymd_hms(2012, 6, 18, 10, 30, 0),
                ymd_hms(2012, 6, 22, 10, 30, 0),
                ymd_hms(2013, 6, 3, 10, 30, 0),
            ],
        );
    }
}