diff options
-rw-r--r-- | src/main.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 28575d5..0a52dc3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,8 +62,18 @@ fn read_icalendar_from_file(filename: &str) -> std::io::Result<Vec<ical::parser: .collect()) } -fn match_event(_event: &ical::parser::ical::component::IcalEvent, _pattern: &str) -> bool { - true +fn match_event(event: &ical::parser::ical::component::IcalEvent, pattern: &str) -> bool { + if pattern == "*" { + true + } + else { + let parts: Vec<&str> = pattern.split(':').collect(); + let (key, pat) = (parts[0].to_uppercase(), parts[1]); + + event.properties.iter() + .filter(|ref p| p.name == key && &p.value.clone().unwrap().matches(&pat).count() > &0) + .count() > 0 + } } #[test] @@ -74,6 +84,14 @@ fn match_all_events() { assert_eq!(num_events, 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()); +} + fn main() { let calendars = read_icalendar_from_file("test.ics").unwrap(); println!("Found {} calendard in file...", calendars.len()); |