1generate_elem_id!(
8 Nick,
10 "nick",
11 NICK
12);
13
14#[cfg(test)]
15mod tests {
16 use super::*;
17 use minidom::Element;
18 #[cfg(not(feature = "disable-validation"))]
19 use xso::error::{Error, FromElementError};
20
21 #[cfg(target_pointer_width = "32")]
22 #[test]
23 fn test_size() {
24 assert_size!(Nick, 12);
25 }
26
27 #[cfg(target_pointer_width = "64")]
28 #[test]
29 fn test_size() {
30 assert_size!(Nick, 24);
31 }
32
33 #[test]
34 fn test_simple() {
35 let elem: Element = "<nick xmlns='http://jabber.org/protocol/nick'>Link Mauve</nick>"
36 .parse()
37 .unwrap();
38 let nick = Nick::try_from(elem).unwrap();
39 assert_eq!(&nick.0, "Link Mauve");
40 }
41
42 #[test]
43 fn test_serialise() {
44 let elem1 = Element::from(Nick(String::from("Link Mauve")));
45 let elem2: Element = "<nick xmlns='http://jabber.org/protocol/nick'>Link Mauve</nick>"
46 .parse()
47 .unwrap();
48 assert_eq!(elem1, elem2);
49 }
50
51 #[cfg(not(feature = "disable-validation"))]
52 #[test]
53 fn test_invalid() {
54 let elem: Element = "<nick xmlns='http://jabber.org/protocol/nick'><coucou/></nick>"
55 .parse()
56 .unwrap();
57 let error = Nick::try_from(elem).unwrap_err();
58 let message = match error {
59 FromElementError::Invalid(Error::Other(string)) => string,
60 _ => panic!(),
61 };
62 assert_eq!(message, "Unknown child in Nick element.");
63 }
64
65 #[cfg(not(feature = "disable-validation"))]
66 #[test]
67 fn test_invalid_attribute() {
68 let elem: Element = "<nick xmlns='http://jabber.org/protocol/nick' coucou=''/>"
69 .parse()
70 .unwrap();
71 let error = Nick::try_from(elem).unwrap_err();
72 let message = match error {
73 FromElementError::Invalid(Error::Other(string)) => string,
74 _ => panic!(),
75 };
76 assert_eq!(message, "Unknown attribute in Nick element.");
77 }
78}