component.rs

 1// Copyright (c) 2018 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
 2//
 3// This Source Code Form is subject to the terms of the Mozilla Public
 4// License, v. 2.0. If a copy of the MPL was not distributed with this
 5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
 6
 7use try_from::TryFrom;
 8
 9use minidom::Element;
10use error::Error;
11use helpers::PlainText;
12use ns;
13
14generate_element_with_text!(Handshake, "handshake", ns::COMPONENT,
15    data: PlainText<Option<String>>
16);
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21
22    #[test]
23    fn test_simple() {
24        let elem: Element = "<handshake xmlns='jabber:component:accept'/>".parse().unwrap();
25        let handshake = Handshake::try_from(elem).unwrap();
26        assert_eq!(handshake.data, None);
27
28        let elem: Element = "<handshake xmlns='jabber:component:accept'>Coucou</handshake>".parse().unwrap();
29        let handshake = Handshake::try_from(elem).unwrap();
30        assert_eq!(handshake.data, Some(String::from("Coucou")));
31    }
32}