diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-12-18 14:21:06 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-12-18 14:53:53 +0100 |
commit | 9545d88f026d793a74b3b26c5ec7c085311eeb61 (patch) | |
tree | d729b9208a5200c7dab6a95e7e915156450cd82c | |
parent | 183abd3316532531d5510e4ea7b87aeb1404a4a2 (diff) | |
download | icaltool-9545d88f026d793a74b3b26c5ec7c085311eeb61.tar.gz icaltool-9545d88f026d793a74b3b26c5ec7c085311eeb61.tar.bz2 icaltool-9545d88f026d793a74b3b26c5ec7c085311eeb61.zip |
Move common test code into function.
-rw-r--r-- | src/main.rs | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index 0a52dc3..f6aec5c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,20 +76,31 @@ fn match_event(event: &ical::parser::ical::component::IcalEvent, pattern: &str) } } +#[cfg(test)] +fn test_match_event_helper(pattern: &str) -> Vec<ical::parser::ical::component::IcalEvent> { + let cal = read_icalendar_from_file("test/fixtures/events.ics").unwrap(); + cal[0].events.iter() + .filter_map(|event| { + if match_event(&event, pattern) { + Some(event.clone()) + } + else { + None + } + }) + .collect() +} + #[test] fn match_all_events() { - let cal = read_icalendar_from_file("test/fixtures/events.ics").unwrap(); - let num_events = cal[0].events.len(); - let events:Vec<_> = cal[0].events.iter().filter(|ref event| match_event(&event, "*")).collect(); - assert_eq!(num_events, events.len()); + let events:Vec<_> = test_match_event_helper("*"); + assert_eq!(3, events.len()); } #[test] fn match_events_by_summary() { - let cal = read_icalendar_from_file("test/fixtures/events.ics").unwrap(); - let num_events = cal[0].events.len(); - let events:Vec<_> = cal[0].events.iter().filter(|ref event| match_event(&event, "summary:All")).collect(); - assert_eq!(num_events - 1, events.len()); + let events:Vec<_> = test_match_event_helper("summary:All"); + assert_eq!(2, events.len()); } fn main() { |