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
7use try_from::TryFrom;
8
9use minidom::Element;
10
11use error::Error;
12
13use ns;
14
15generate_empty_element!(Attention, "attention", ns::ATTENTION);
16
17#[cfg(test)]
18mod tests {
19 use super::*;
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}