aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.rs27
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() {