From c584137ee54abcb3c5a9bb93e36c204b2b14fbd2 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Sat, 6 Apr 2024 14:23:57 -0700 Subject: [PATCH] Add support for comments --- instant-xml/src/de.rs | 1 + instant-xml/tests/direct.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/instant-xml/src/de.rs b/instant-xml/src/de.rs index 9952ddb..ab770fc 100644 --- a/instant-xml/src/de.rs +++ b/instant-xml/src/de.rs @@ -353,6 +353,7 @@ impl<'xml> Iterator for Context<'xml> { false => return Some(Err(Error::UnexpectedToken(format!("{token:?}")))), true => {} }, + Ok(Token::Comment { .. }) => continue, Ok(token) => return Some(Err(Error::UnexpectedToken(format!("{token:?}")))), Err(e) => return Some(Err(Error::Parse(e))), } diff --git a/instant-xml/tests/direct.rs b/instant-xml/tests/direct.rs index 8b34b1b..17e1f28 100644 --- a/instant-xml/tests/direct.rs +++ b/instant-xml/tests/direct.rs @@ -2,7 +2,7 @@ use similar_asserts::assert_eq; use instant_xml::{from_str, to_string, FromXml, ToXml}; -#[derive(Debug, Eq, FromXml, PartialEq, ToXml)] +#[derive(Clone, Debug, Eq, FromXml, PartialEq, ToXml)] struct Foo { #[xml(attribute)] flag: bool, @@ -19,5 +19,14 @@ fn direct() { let xml = "cbdté"; assert_eq!(to_string(&v).unwrap(), xml); + assert_eq!(from_str::(xml), Ok(v.clone())); + + let xml = "cbdté"; + assert_eq!(from_str::(xml), Ok(v.clone())); + + let xml = "cbdté"; + assert_eq!(from_str::(xml), Ok(v.clone())); + + let xml = "cbdté"; assert_eq!(from_str::(xml), Ok(v)); }