Add support for comments

This commit is contained in:
Nicholas Rempel 2024-04-06 14:23:57 -07:00 committed by Nick Rempel
parent a199cc7b5c
commit c584137ee5
2 changed files with 11 additions and 1 deletions

View File

@ -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))),
}

View File

@ -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 = "<Foo flag=\"true\">cbdté</Foo>";
assert_eq!(to_string(&v).unwrap(), xml);
assert_eq!(from_str::<Foo>(xml), Ok(v.clone()));
let xml = "<Foo flag=\"true\"><!--comment-->cbdté</Foo>";
assert_eq!(from_str::<Foo>(xml), Ok(v.clone()));
let xml = "<Foo flag=\"true\"><!--comment--><!--comment-->cbdté</Foo>";
assert_eq!(from_str::<Foo>(xml), Ok(v.clone()));
let xml = "<!--comment--><Foo flag=\"true\"><!--comment-->cbdté</Foo><!--comment-->";
assert_eq!(from_str::<Foo>(xml), Ok(v));
}