summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/rrule.rs72
1 files changed, 29 insertions, 43 deletions
diff --git a/tests/rrule.rs b/tests/rrule.rs
index ca171db..4f96320 100644
--- a/tests/rrule.rs
+++ b/tests/rrule.rs
@@ -3,12 +3,24 @@ 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,
@@ -19,6 +31,13 @@ mod test {
};
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);
}
@@ -26,51 +45,18 @@ mod test {
#[test]
fn int_works() {
- let mut options = ParsedOptions {
- freq: Frequenzy::DAILY,
- dtstart: Utc.ymd(2012, 1, 1).and_hms(10, 30, 0),
- until: Some(Utc.ymd(2012, 12, 31).and_hms(10, 30, 0)),
- tzid: None,
- interval: 1,
- wkst: 0,
- count: None,
- bysecond: vec![0],
- byminute: vec![30],
- byhour: vec![10],
- bymonth: vec![],
- bymonthday: vec![],
- bysetpos: vec![],
- byweekno: vec![],
- byyearday: vec![],
- byweekday: vec![0, 1, 2, 3, 4, 5, 6],
- bynweekday: vec![],
- bynmonthday: vec![],
- };
- let mut options_2 = ParsedOptions {
- freq: Frequenzy::WEEKLY,
- dtstart: Utc.ymd(2012, 1, 1).and_hms(10, 30, 0),
- until: None,
- //until: Some(Utc.ymd(2012, 12, 31).and_hms(10, 30, 0)),
- tzid: None,
- interval: 5,
- wkst: 0,
- count: Some(3),
- bysecond: vec![0],
- byminute: vec![30],
- byhour: vec![10],
- bymonth: vec![6],
- bymonthday: vec![],
- bysetpos: vec![],
- byweekno: vec![],
- byyearday: vec![],
- byweekday: vec![0, 4],
- bynweekday: vec![],
- bynmonthday: vec![],
- };
+ 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_2,
- &vec![Utc.ymd(2020, 0, 0).and_hms(0, 0, 0)],
+ &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),
+ ],
);
}
}