From 6c265a53f05fd52ce16125fb40563c0309a15042 Mon Sep 17 00:00:00 2001 From: Seth Westphal Date: Mon, 15 Jan 2024 12:01:02 -0600 Subject: [PATCH] Add test to verify parser handles \r\n. --- tests/mod.rs | 23 ++++++++++++++ tests/ressources/ical_example_2.ics | 47 +++++++++++++++++++++++++++++ tests/ressources/ical_example_2.res | 35 +++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 tests/ressources/ical_example_2.ics create mode 100644 tests/ressources/ical_example_2.res diff --git a/tests/mod.rs b/tests/mod.rs index a9ab96c..a5e694c 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -162,6 +162,29 @@ pub mod parser { } } + #[test] + // same as ical_example_1 but with \r\n endings instead of \n. + fn ical_example_2() { + let input = BufReader::new(File::open("./tests/ressources/ical_example_2.ics").unwrap()); + + let valids = std::fs::read_to_string("./tests/ressources/ical_example_2.res") + .unwrap() + .replace('\n', ""); + + let reader = ical::IcalParser::new(input); + + for res in reader { + let calendar = match res { + Ok(res) => res, + Err(err) => panic!("{}", err), + }; + + let output = format!("{:?}", calendar); + + assert_eq!(output, valids); + } + } + #[test] fn vcard() { let input = BufReader::new(File::open("./tests/ressources/vcard_input.vcf").unwrap()); diff --git a/tests/ressources/ical_example_2.ics b/tests/ressources/ical_example_2.ics new file mode 100644 index 0000000..19b1860 --- /dev/null +++ b/tests/ressources/ical_example_2.ics @@ -0,0 +1,47 @@ +BEGIN:VCALENDAR +PRODID:-//Microsoft Corporation//Outlook 16.0 MIMEDIR//EN +VERSION:2.0 +METHOD:PUBLISH +X-MS-OLK-FORCEINSPECTOROPEN:TRUE +BEGIN:VTIMEZONE +TZID:W. Europe Standard Time +BEGIN:STANDARD +DTSTART:16011028T030000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10 +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:16010325T020000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3 +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VEVENT +CLASS:PUBLIC +CREATED:20210511T063845Z +DESCRIPTION:Einwahldaten folgen in der Veranstaltungswoche \nSeminartitel: + Software-QS-Cast - Application Performance Monitoring\nDatum: 27.Mai 2021\ + nUhrzeit: 10:30 - ca.12:00 Uhr \n \n +DTEND;TZID="W. Europe Standard Time":20210527T120000 +DTSTAMP:20210511T063845Z +DTSTART;TZID="W. Europe Standard Time":20210527T103000 +LAST-MODIFIED:20210511T063845Z +PRIORITY:5 +SEQUENCE:0 +SUMMARY;LANGUAGE=de:Software-QS-Cast Application Performance Monitoring +TRANSP:OPAQUE +UID:040000008200E000*************00800000000*****************00000000000000 + 010000000******************************** +X-MICROSOFT-CDO-BUSYSTATUS:BUSY +X-MICROSOFT-CDO-IMPORTANCE:1 +X-MICROSOFT-DISALLOW-COUNTER:FALSE +X-MS-OLK-CONFTYPE:0 +BEGIN:VALARM +TRIGGER:-PT15M +ACTION:DISPLAY +DESCRIPTION:Reminder +END:VALARM +END:VEVENT +END:VCALENDAR diff --git a/tests/ressources/ical_example_2.res b/tests/ressources/ical_example_2.res new file mode 100644 index 0000000..1341678 --- /dev/null +++ b/tests/ressources/ical_example_2.res @@ -0,0 +1,35 @@ +IcalCalendar { + properties: [ +Property { name: "PRODID", params: None, value: Some("-//Microsoft Corporation//Outlook 16.0 MIMEDIR//EN") }, + Property { name: "VERSION", params: None, value: Some("2.0") }, + Property { name: "METHOD", params: None, value: Some("PUBLISH") }, + Property { name: "X-MS-OLK-FORCEINSPECTOROPEN", params: None, value: Some("TRUE") }], + events: [ +IcalEvent { properties: [ +Property { name: "CLASS", params: None, value: Some("PUBLIC") }, + Property { name: "CREATED", params: None, value: Some("20210511T063845Z") }, + Property { name: "DESCRIPTION", params: None, value: Some("Einwahldaten folgen in der Veranstaltungswoche \\nSeminartitel:Software-QS-Cast - Application Performance Monitoring\\nDatum: 27.Mai 2021\\nUhrzeit: 10:30 - ca.12:00 Uhr \\n \\n") }, + Property { name: "DTEND", params: Some([("TZID", ["W. Europe Standard Time"])]), value: Some("20210527T120000") }, + Property { name: "DTSTAMP", params: None, value: Some("20210511T063845Z") }, + Property { name: "DTSTART", params: Some([("TZID", ["W. Europe Standard Time"])]), value: Some("20210527T103000") }, + Property { name: "LAST-MODIFIED", params: None, value: Some("20210511T063845Z") }, + Property { name: "PRIORITY", params: None, value: Some("5") }, Property { name: "SEQUENCE", params: None, value: Some("0") }, + Property { name: "SUMMARY", params: Some([("LANGUAGE", ["de"])]), value: Some("Software-QS-Cast Application Performance Monitoring") }, + Property { name: "TRANSP", params: None, value: Some("OPAQUE") }, + Property { name: "UID", params: None, value: Some("040000008200E000*************00800000000*****************00000000000000010000000********************************") }, + Property { name: "X-MICROSOFT-CDO-BUSYSTATUS", params: None, value: Some("BUSY") }, + Property { name: "X-MICROSOFT-CDO-IMPORTANCE", params: None, value: Some("1") }, + Property { name: "X-MICROSOFT-DISALLOW-COUNTER", params: None, value: Some("FALSE") }, + Property { name: "X-MS-OLK-CONFTYPE", params: None, value: Some("0") }], + alarms: [ +IcalAlarm { properties: [ +Property { name: "TRIGGER", params: None, value: Some("-PT15M") }, + Property { name: "ACTION", params: None, value: Some("DISPLAY") }, + Property { name: "DESCRIPTION", params: None, value: Some("Reminder") }] }] }], + alarms: [], todos: [], journals: [], free_busys: [], + timezones: [IcalTimeZone { properties: [Property { name: "TZID", params: None, value: Some("W. Europe Standard Time") }], + transitions: [IcalTimeZoneTransition { transition: STANDARD, properties: [Property { name: "DTSTART", params: None, value: Some("16011028T030000") }, + Property { name: "RRULE", params: None, value: Some("FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10") }, + Property { name: "TZOFFSETFROM", params: None, value: Some("+0200") }, + Property { name: "TZOFFSETTO", params: None, value: Some("+0100") }] }, + IcalTimeZoneTransition { transition: DAYLIGHT, properties: [Property { name: "DTSTART", params: None, value: Some("16010325T020000") }, Property { name: "RRULE", params: None, value: Some("FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3") }, Property { name: "TZOFFSETFROM", params: None, value: Some("+0100") }, Property { name: "TZOFFSETTO", params: None, value: Some("+0200") }] }] }] }