xmpp-rs-mirror/src/component.rs

33 lines
996 B
Rust
Raw Normal View History

2018-03-01 09:57:01 +00:00
// Copyright (c) 2018 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use try_from::TryFrom;
use minidom::Element;
use error::Error;
use helpers::PlainText;
2018-03-01 09:57:01 +00:00
use ns;
generate_element_with_text!(Handshake, "handshake", ns::COMPONENT,
data: PlainText<Option<String>>
2018-03-01 09:57:01 +00:00
);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_simple() {
let elem: Element = "<handshake xmlns='jabber:component:accept'/>".parse().unwrap();
let handshake = Handshake::try_from(elem).unwrap();
assert_eq!(handshake.data, None);
2018-03-01 09:57:01 +00:00
let elem: Element = "<handshake xmlns='jabber:component:accept'>Coucou</handshake>".parse().unwrap();
2018-03-01 09:57:01 +00:00
let handshake = Handshake::try_from(elem).unwrap();
assert_eq!(handshake.data, Some(String::from("Coucou")));
2018-03-01 09:57:01 +00:00
}
}