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