chatstates: Add a serialise function.
This commit is contained in:
parent
7002578bc0
commit
4128c4b9ed
1 changed files with 19 additions and 0 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue