use anyhow::Result;
use html_parser_tarasenko::{parse_html, Node};
#[test]
fn test_empty_html() -> Result<()> {
let input = "";
let result = parse_html(input)?;
assert!(result.is_empty());
Ok(())
}
#[test]
fn test_simple_element() -> Result<()> {
let input = "
Unclosed tag";
let result = parse_html(input);
assert!(result.is_err());
}
#[test]
fn test_html() -> Result<()> {
assert!(
html_parser_tarasenko::parse_html("
Hello World!
").is_ok()
);
assert!(html_parser_tarasenko::parse_html("
").is_ok());
assert!(
html_parser_tarasenko::parse_html("
Hello World!").is_err()
);
assert!(html_parser_tarasenko::parse_html("
Hello World!").is_err());
Ok(())
}
#[test]
fn test_elements() -> Result<()> {
assert!(
html_parser_tarasenko::parse("elements", "
Paragraph
").is_ok()
);
assert!(html_parser_tarasenko::parse("elements", "
").is_ok());
Ok(())
}
#[test]
fn test_element() -> Result<()> {
assert!(html_parser_tarasenko::parse("element", "
Text
").is_ok());
assert!(html_parser_tarasenko::parse("element", "
Nested
").is_ok());
assert!(html_parser_tarasenko::parse("element", "
Text").is_err());
assert!(html_parser_tarasenko::parse("element", "
Nested
").is_err());
Ok(())
}
#[test]
fn test_opening_tag() -> Result<()> {
assert!(html_parser_tarasenko::parse("opening_tag", "
").is_ok());
assert!(html_parser_tarasenko::parse("opening_tag", "
").is_ok());
assert!(html_parser_tarasenko::parse("opening_tag", "
").is_err());
Ok(())
}
#[test]
fn test_closing_tag() -> Result<()> {
assert!(html_parser_tarasenko::parse("closing_tag", "
").is_ok());
assert!(html_parser_tarasenko::parse("closing_tag", "").is_ok());
assert!(html_parser_tarasenko::parse("closing_tag", "
").is_err());
Ok(())
}
#[test]
fn test_self_closed_tag_second_test() -> Result<()> {
assert!(html_parser_tarasenko::parse("self_closed_tag", "
").is_ok());
assert!(html_parser_tarasenko::parse("self_closed_tag", "
").is_ok());
assert!(html_parser_tarasenko::parse("self_closed_tag", "
").is_err());
assert!(html_parser_tarasenko::parse("self_closed_tag", "
Result<()> {
assert!(html_parser_tarasenko::parse("tag_name", "div").is_ok());
assert!(html_parser_tarasenko::parse("tag_name", "img1").is_ok());
assert!(html_parser_tarasenko::parse("tag_name", "123").is_err());
Ok(())
}
#[test]
fn test_attribute_list() -> Result<()> {
assert!(html_parser_tarasenko::parse(
"attribute_list",
"src=\"image.jpg\" alt=\"description\""
)
.is_ok());
assert!(html_parser_tarasenko::parse("attribute_list", "class=\"container\"").is_ok());
Ok(())
}
#[test]
fn test_attribute() -> Result<()> {
assert!(html_parser_tarasenko::parse("attribute", "src=\"image.jpg\"").is_ok());
assert!(html_parser_tarasenko::parse("attribute", "alt=\"description\"").is_ok());
assert!(html_parser_tarasenko::parse("attribute", "src=image.jpg").is_err());
assert!(html_parser_tarasenko::parse("attribute", "alt='description'").is_err());
Ok(())
}
#[test]
fn test_identifier() -> Result<()> {
assert!(html_parser_tarasenko::parse("identifier", "src").is_ok());
assert!(html_parser_tarasenko::parse("identifier", "class").is_ok());
assert!(html_parser_tarasenko::parse("identifier", "123class").is_err());
Ok(())
}
#[test]
fn test_quoted_string() -> Result<()> {
assert!(html_parser_tarasenko::parse("quoted_string", "\"image.jpg\"").is_ok());
assert!(html_parser_tarasenko::parse("quoted_string", "\"description\"").is_ok());
assert!(html_parser_tarasenko::parse("quoted_string", "image.jpg").is_err());
assert!(html_parser_tarasenko::parse("quoted_string", "\"unclosed string").is_err());
Ok(())
}
#[test]
fn test_content() -> Result<()> {
assert!(html_parser_tarasenko::parse("content", "Text").is_ok());
assert!(html_parser_tarasenko::parse("content", "
Paragraph
Nested text").is_ok());
Ok(())
}
#[test]
fn test_text() -> Result<()> {
assert!(html_parser_tarasenko::parse("text", "Hello World!").is_ok());
assert!(html_parser_tarasenko::parse("text", "Plain text with spaces").is_ok());
assert!(html_parser_tarasenko::parse("text", "
").is_err());
Ok(())
}
#[test]
fn test_whitespace() -> Result<()> {
assert!(html_parser_tarasenko::parse("WHITESPACE", " ").is_ok());
assert!(html_parser_tarasenko::parse("WHITESPACE", "\t\n\r").is_ok());
assert!(html_parser_tarasenko::parse("WHITESPACE", "a").is_err());
Ok(())
}