attention.rs

 1// Copyright (c) 2017 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
 7#![deny(missing_docs)]
 8
 9generate_empty_element!(
10    /// Requests the attention of the recipient.
11    Attention, "attention", ATTENTION
12);
13
14#[cfg(test)]
15mod tests {
16    use super::*;
17    use try_from::TryFrom;
18    use minidom::Element;
19    use error::Error;
20
21    #[test]
22    fn test_simple() {
23        let elem: Element = "<attention xmlns='urn:xmpp:attention:0'/>".parse().unwrap();
24        Attention::try_from(elem).unwrap();
25    }
26
27    #[test]
28    fn test_invalid_child() {
29        let elem: Element = "<attention xmlns='urn:xmpp:attention:0'><coucou/></attention>".parse().unwrap();
30        let error = Attention::try_from(elem).unwrap_err();
31        let message = match error {
32            Error::ParseError(string) => string,
33            _ => panic!(),
34        };
35        assert_eq!(message, "Unknown child in attention element.");
36    }
37
38    #[test]
39    fn test_invalid_attribute() {
40        let elem: Element = "<attention xmlns='urn:xmpp:attention:0' coucou=''/>".parse().unwrap();
41        let error = Attention::try_from(elem).unwrap_err();
42        let message = match error {
43            Error::ParseError(string) => string,
44            _ => panic!(),
45        };
46        assert_eq!(message, "Unknown attribute in attention element.");
47    }
48
49    #[test]
50    fn test_serialise() {
51        let elem: Element = "<attention xmlns='urn:xmpp:attention:0'/>".parse().unwrap();
52        let attention = Attention;
53        let elem2: Element = attention.into();
54        assert_eq!(elem, elem2);
55    }
56}