1use minidom::Element;
2
3use error::Error;
4
5use ns;
6
7#[derive(Debug, Clone)]
8pub enum Attention {
9 Attention,
10}
11
12pub fn parse_attention(root: &Element) -> Result<Attention, Error> {
13 if !root.is("attention", ns::ATTENTION) {
14 return Err(Error::ParseError("This is not an attention element."));
15 }
16 for _ in root.children() {
17 return Err(Error::ParseError("Unknown child in attention element."));
18 }
19 Ok(Attention::Attention)
20}
21
22#[cfg(test)]
23mod tests {
24 use minidom::Element;
25 use error::Error;
26 use attention;
27
28 #[test]
29 fn test_simple() {
30 let elem: Element = "<attention xmlns='urn:xmpp:attention:0'/>".parse().unwrap();
31 attention::parse_attention(&elem).unwrap();
32 }
33
34 #[test]
35 fn test_invalid_child() {
36 let elem: Element = "<attention xmlns='urn:xmpp:attention:0'><coucou/></attention>".parse().unwrap();
37 let error = attention::parse_attention(&elem).unwrap_err();
38 let message = match error {
39 Error::ParseError(string) => string,
40 _ => panic!(),
41 };
42 assert_eq!(message, "Unknown child in attention element.");
43 }
44}