use anyhow::{anyhow, Result}; use html_simple_parser::{parse_html, HtmlElem, HtmlParseError}; #[test] fn thow_mismatched_closing_tag_error() -> Result<()> { let input = "
"; let result = parse_html(input); match result { Ok(_) => Err(anyhow!( "Test failed! There should be an error here due to tag mismatch." )), Err(HtmlParseError::MismatchedClosingTag(expected, found)) => { assert_eq!(expected, "html"); assert_eq!(found, "div"); Ok(()) } Err(err) => Err(anyhow!(err).context("Test failed! Not the error that was expected.")), } } #[test] fn invalid_html_structure() -> Result<()> { let input = " "; let result = parse_html(input); match result { Ok(_) => Err(anyhow!( "Test failed! There should be an error here due to invalid structure." )), Err(HtmlParseError::ErrorHtmlStructure) => Ok(()), Err(err) => Err(anyhow!(err).context("Test failed! Not the error that was expected.")), } } #[test] fn defining_right_tags() -> Result<()> { let input = "Text
should contain text." )); } } _ => { return Err(anyhow!( "Test failed! The first child of
should be a tag."
))
}
}
match &children[1] {
HtmlElem::Tag { tag_name, children } => {
assert_eq!(tag_name, "
");
assert!(children.is_empty());
}
_ => {
return Err(anyhow!(
"Test failed! The second child of