chatstates: Add a serialise function.

This commit is contained in:
Emmanuel Gil Peyrot 2017-04-23 03:22:42 +01:00
parent 7002578bc0
commit 4128c4b9ed

View file

@ -32,11 +32,23 @@ pub fn parse_chatstate(root: &Element) -> Result<ChatState, Error> {
}
}
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));
}
}