diff --git a/src/delay.rs b/src/delay.rs index b54dd04..54fa7e8 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -31,6 +31,15 @@ pub fn parse_delay(root: &Element) -> Result { }) } +pub fn serialise(delay: &Delay) -> Element { + Element::builder("delay") + .ns(ns::DELAY) + .attr("from", delay.from.clone()) + .attr("stamp", delay.stamp.clone()) + .append(delay.data.clone()) + .build() +} + #[cfg(test)] mod tests { use minidom::Element; @@ -67,4 +76,28 @@ mod tests { }; assert_eq!(message, "Unknown child in delay element."); } + + #[test] + fn test_serialise() { + let elem: Element = "".parse().unwrap(); + let delay = delay::Delay { + from: None, + stamp: "2002-09-10T23:08:25Z".to_owned(), + data: None, + }; + let elem2 = delay::serialise(&delay); + assert_eq!(elem, elem2); + } + + #[test] + fn test_serialise_data() { + let elem: Element = "Reason".parse().unwrap(); + let delay = delay::Delay { + from: Some(String::from("juliet@example.org")), + stamp: "2002-09-10T23:08:25Z".to_owned(), + data: Some(String::from("Reason")), + }; + let elem2 = delay::serialise(&delay); + assert_eq!(elem, elem2); + } }