From c6036194b1f2fbcc24bc7212533d18adb0b064ab Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 23 Apr 2017 03:21:53 +0100 Subject: [PATCH] delay: Add a serialise function. --- src/delay.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/delay.rs b/src/delay.rs index b54dd047..54fa7e87 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); + } }