From 4276090314207f36a7608976e7271682157ae41d Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Sun, 3 Mar 2024 11:26:32 +0100 Subject: WIP testing --- src/dav/calencoder.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 10 deletions(-) diff --git a/src/dav/calencoder.rs b/src/dav/calencoder.rs index 05d0454..f5f4924 100644 --- a/src/dav/calencoder.rs +++ b/src/dav/calencoder.rs @@ -677,27 +677,82 @@ impl QuickWritable for TimeRange { #[cfg(test)] mod tests { use super::*; - use crate::dav::types::{Error, Violation as DavViolation}; + use crate::dav::types as dav; use tokio::io::AsyncWriteExt; - #[tokio::test] - async fn test_violation() { + async fn serialize>(ctx: C, elem: &Q) -> String { let mut buffer = Vec::new(); let mut tokio_buffer = tokio::io::BufWriter::new(&mut buffer); let mut writer = Writer::new_with_indent(&mut tokio_buffer, b' ', 4); + elem.write(&mut writer, ctx).await.expect("xml serialization"); + tokio_buffer.flush().await.expect("tokio buffer flush"); + let got = std::str::from_utf8(buffer.as_slice()).unwrap(); - let res = Error(vec![ - DavViolation::Extension(Violation::ResourceMustBeNull), - ]); + return got.into() + } - res.write(&mut writer, CalExtension { root: true }).await.expect("xml serialization"); - tokio_buffer.flush().await.expect("tokio buffer flush"); + #[tokio::test] + async fn basic_violation() { + let got = serialize( + CalExtension { root: true }, + &dav::Error(vec![ + dav::Violation::Extension(Violation::ResourceMustBeNull), + ]) + ).await; let expected = r#" "#; - let got = std::str::from_utf8(buffer.as_slice()).unwrap(); - assert_eq!(got, expected); + assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n"); + } + + #[tokio::test] + async fn rfc_calendar_query1() { + let got = serialize( + CalExtension { root: true }, + &CalendarQuery { + selector: Some(CalendarSelector::Prop(dav::PropName(vec![ + ]))), + filter: Filter(CompFilter { + name: Component::VCalendar, + additional_rules: None, + }), + timezone: None, + } + ).await; + + let expected = r#" + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"#; + + assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n"); } } -- cgit v1.2.3