From 5ec921fa6fa5a0e9888396286c593c45d80ba240 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 20 Jul 2017 20:11:00 +0100 Subject: [PATCH] attention: Add missing unknown attribute check. --- src/attention.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/attention.rs b/src/attention.rs index c53040c..333d190 100644 --- a/src/attention.rs +++ b/src/attention.rs @@ -25,6 +25,9 @@ impl TryFrom for Attention { for _ in elem.children() { return Err(Error::ParseError("Unknown child in attention element.")); } + for _ in elem.attrs() { + return Err(Error::ParseError("Unknown attribute in attention element.")); + } Ok(Attention) } } @@ -61,6 +64,17 @@ mod tests { assert_eq!(message, "Unknown child in attention element."); } + #[test] + fn test_invalid_attribute() { + let elem: Element = "".parse().unwrap(); + let error = Attention::try_from(elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Unknown attribute in attention element."); + } + #[test] fn test_serialise() { let elem: Element = "".parse().unwrap();