From 4128c4b9edec6483189dd8d73729b4bb9a39f6f9 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 23 Apr 2017 03:22:42 +0100 Subject: [PATCH] chatstates: Add a serialise function. --- src/chatstates.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/chatstates.rs b/src/chatstates.rs index 8732d565..7632086e 100644 --- a/src/chatstates.rs +++ b/src/chatstates.rs @@ -32,11 +32,23 @@ pub fn parse_chatstate(root: &Element) -> Result { } } +pub fn serialise(chatstate: &ChatState) -> Element { + Element::builder(match *chatstate { + ChatState::Active => "active", + ChatState::Composing => "composing", + ChatState::Gone => "gone", + ChatState::Inactive => "inactive", + ChatState::Paused => "paused", + }).ns(ns::CHATSTATES) + .build() +} + #[cfg(test)] mod tests { use minidom::Element; use error::Error; use chatstates; + use ns; #[test] fn test_simple() { @@ -77,4 +89,11 @@ mod tests { }; assert_eq!(message, "Unknown attribute in chatstate element."); } + + #[test] + fn test_serialise() { + let chatstate = chatstates::ChatState::Active; + let elem = chatstates::serialise(&chatstate); + assert!(elem.is("active", ns::CHATSTATES)); + } }