From e0e6119e55bb3db0da1c94457696824e252d245b Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 20 Apr 2017 21:02:51 +0100 Subject: [PATCH] disco: Relax the parsing rules for get disco#info. --- src/disco.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/disco.rs b/src/disco.rs index 3100d4b..afb1fa7 100644 --- a/src/disco.rs +++ b/src/disco.rs @@ -85,6 +85,8 @@ pub fn parse_disco(root: &Element) -> Result { } } + /* + // TODO: encode these restrictions only for result disco#info, not get ones. if identities.is_empty() { return Err(Error::ParseError("There must be at least one identity in disco#info.")); } @@ -94,6 +96,7 @@ pub fn parse_disco(root: &Element) -> Result { if !features.contains(&Feature { var: DISCO_INFO_NS.to_owned() }) { return Err(Error::ParseError("disco#info feature not present in disco#info.")); } + */ return Ok(Disco { node: node, @@ -128,15 +131,10 @@ mod tests { _ => panic!(), }; assert_eq!(message, "Unknown element in disco#info."); + } - let elem: Element = "".parse().unwrap(); - let error = disco::parse_disco(&elem).unwrap_err(); - let message = match error { - Error::ParseError(string) => string, - _ => panic!(), - }; - assert_eq!(message, "There must be at least one identity in disco#info."); - + #[test] + fn test_invalid_identity() { let elem: Element = "".parse().unwrap(); let error = disco::parse_disco(&elem).unwrap_err(); let message = match error { @@ -168,7 +166,10 @@ mod tests { _ => panic!(), }; assert_eq!(message, "Identity must have a non-empty 'type' attribute."); + } + #[test] + fn test_invalid_feature() { let elem: Element = "".parse().unwrap(); let error = disco::parse_disco(&elem).unwrap_err(); let message = match error { @@ -176,6 +177,18 @@ mod tests { _ => panic!(), }; assert_eq!(message, "Feature must have a 'var' attribute."); + } + + #[test] + #[ignore] + fn test_invalid_result() { + let elem: Element = "".parse().unwrap(); + let error = disco::parse_disco(&elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "There must be at least one identity in disco#info."); let elem: Element = "".parse().unwrap(); let error = disco::parse_disco(&elem).unwrap_err();