From 9d129701d09983898d059575312b8fc0b4e81a11 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 19 Apr 2017 02:38:10 +0100 Subject: [PATCH] jingle: Add an error when there is more than one in a . --- src/jingle.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/jingle.rs b/src/jingle.rs index e732c6b4..37912a02 100644 --- a/src/jingle.rs +++ b/src/jingle.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use minidom::Element; use error::Error; -use ns::{JINGLE_NS}; +use ns::JINGLE_NS; #[derive(Debug, PartialEq)] pub enum Action { @@ -285,6 +285,9 @@ pub fn parse_jingle(root: &Element) -> Result { } let name = stuff.name(); if name == "text" { + if text.is_some() { + return Err(Error::ParseError("Reason must not have more than one text.")); + } text = Some(stuff.text()); } else { reason = Some(name.parse()?); @@ -487,5 +490,13 @@ mod tests { _ => panic!(), }; assert_eq!(message, "Jingle must not have more than one reason."); + + let elem: Element = "".parse().unwrap(); + let error = jingle::parse_jingle(&elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Reason must not have more than one text."); } }