Added a parsing/building round-trip test
This commit is contained in:
parent
39867a9f15
commit
75fe00983d
2 changed files with 61 additions and 0 deletions
|
@ -13,3 +13,44 @@ pub fn default_prod_id() -> String {
|
||||||
format!("-//{}//{}//EN", ORG_NAME, PRODUCT_NAME)
|
format!("-//{}//{}//EN", ORG_NAME, PRODUCT_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use std::collections::HashSet;
|
||||||
|
use crate::item::SyncStatus;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_ical_round_trip_serde() {
|
||||||
|
let ical_with_unknown_fields = std::fs::read_to_string("tests/assets/ical_with_unknown_fields.ics").unwrap();
|
||||||
|
|
||||||
|
let item_id = "http://item.id".parse().unwrap();
|
||||||
|
let sync_status = SyncStatus::NotSynced;
|
||||||
|
let deserialized = parse(&ical_with_unknown_fields, item_id, sync_status).unwrap();
|
||||||
|
let serialized = build_from(&deserialized).unwrap();
|
||||||
|
assert_same_fields(&ical_with_unknown_fields, &serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Assert the properties are present (possibly in another order)
|
||||||
|
/// RFC5545 "imposes no ordering of properties within an iCalendar object."
|
||||||
|
fn assert_same_fields(left: &str, right: &str) {
|
||||||
|
let left_parts: HashSet<&str> = left.split("\r\n").collect();
|
||||||
|
let right_parts: HashSet<&str> = right.split("\r\n").collect();
|
||||||
|
|
||||||
|
// Let's be more explicit than assert_eq!(left_parts, right_parts);
|
||||||
|
if left_parts != right_parts {
|
||||||
|
println!("Only in left:");
|
||||||
|
for item in left_parts.difference(&right_parts) {
|
||||||
|
println!(" * {}", item);
|
||||||
|
}
|
||||||
|
println!("Only in right:");
|
||||||
|
for item in right_parts.difference(&left_parts) {
|
||||||
|
println!(" * {}", item);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(left_parts, right_parts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
20
tests/assets/ical_with_unknown_fields.ics
Normal file
20
tests/assets/ical_with_unknown_fields.ics
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
BEGIN:VCALENDAR
|
||||||
|
VERSION:2.0
|
||||||
|
PRODID:-//Todo Corp LTD//Awesome Product ®//EN
|
||||||
|
BEGIN:VTODO
|
||||||
|
UID:20f57387-e116-4702-b463-d352aeaf80d0
|
||||||
|
X_FAVOURITE_PAINT_FINISH:matte
|
||||||
|
DTSTAMP:20211103T214742
|
||||||
|
CREATED:20211103T212345
|
||||||
|
LAST-MODIFIED:20211103T214742
|
||||||
|
SUMMARY:This is a task with ÜTF-8 characters
|
||||||
|
STATUS:NEEDS-ACTION
|
||||||
|
DUE:20211103T220000
|
||||||
|
PRIORITY:6
|
||||||
|
PERCENT-COMPLETE:48
|
||||||
|
IMAGE;DISPLAY=BADGE;FMTTYPE=image/png;VALUE=URI:http://example.com/images/p
|
||||||
|
arty.png
|
||||||
|
CONFERENCE;FEATURE=PHONE;LABEL=Attendee dial-in;VALUE=URI:tel:+1-888-555-04
|
||||||
|
56,,,555123
|
||||||
|
END:VTODO
|
||||||
|
END:VCALENDAR
|
Loading…
Add table
Reference in a new issue