use html_parser::{Dom, Result}; use indoc::indoc; use insta::assert_json_snapshot; #[test] fn it_can_parse_one_element() -> Result<()> { let html = ""; let dom = Dom::parse(html)?; assert_json_snapshot!(dom); Ok(()) } #[test] fn it_can_parse_one_element_upper_case() -> Result<()> { let html = ""; let dom = Dom::parse(html)?; assert_json_snapshot!(dom); Ok(()) } #[test] fn it_can_parse_one_element_mixed_case() -> Result<()> { let html = ""; let dom = Dom::parse(html)?; assert_json_snapshot!(dom); Ok(()) } #[test] fn it_can_parse_one_element_mixed_case_numbers() -> Result<()> { let html = ""; let dom = Dom::parse(html)?; assert_json_snapshot!(dom); Ok(()) } #[test] fn it_can_parse_one_element_mixed_case_numbers_symbols() -> Result<()> { let html = ""; let dom = Dom::parse(html)?; assert_json_snapshot!(dom); Ok(()) } #[test] fn it_can_parse_multiple_elements() -> Result<()> { let html = "
"; let dom = Dom::parse(html)?; assert_json_snapshot!(dom); Ok(()) } #[test] fn it_can_parse_multiple_open_elements() -> Result<()> { let html = "
"; let dom = Dom::parse(html)?; assert_json_snapshot!(dom); Ok(()) } #[test] fn it_can_parse_nested_elements() -> Result<()> { let html = indoc!( r"
" ); let dom = Dom::parse(html)?; assert_json_snapshot!(dom); Ok(()) } #[test] fn it_can_parse_nested_elements_mixed_children() -> Result<()> { let html = indoc!( r"
Hello
World
" ); let dom = Dom::parse(html)?; assert_json_snapshot!(dom); Ok(()) } #[test] fn it_can_parse_deeply_nested() -> Result<()> { let html = indoc!( r#"
hello world
"# ); let dom = Dom::parse(html)?; assert_json_snapshot!(dom); Ok(()) } #[test] fn it_can_parse_script_with_content() -> Result<()> { let html = indoc!( r#" "# ); let dom = Dom::parse(html)?; assert_json_snapshot!(dom); Ok(()) } #[test] fn it_can_parse_style_with_content() -> Result<()> { let html = indoc!( r#" "# ); let dom = Dom::parse(html)?; assert_json_snapshot!(dom); Ok(()) } #[test] fn it_skips_dangling_elements() -> Result<()> { let html = indoc!( "
" ); let dom = Dom::parse(html)?; assert_json_snapshot!(dom); Ok(()) } #[test] fn it_can_parse_broken_html() -> Result<()> { let html = "
"; let dom = Dom::parse(html)?; assert_json_snapshot!(dom); Ok(()) } #[test] fn it_errors_when_multiple_nested_elements_dont_match() -> Result<()> { let html = "
"; let dom = Dom::parse(html)?; assert_json_snapshot!(dom); Ok(()) } #[test] fn it_can_clone_node() { let html = indoc!( "
one
two
" ); let dom = Dom::parse(html).unwrap(); let one = dom.children[0].clone(); assert_json_snapshot!(one); } #[test] fn it_can_clone_dom() { let html = indoc!( " Title

Hello world

" ); let dom = Dom::parse(html).unwrap(); let dom_clone = dom.clone(); assert_eq!(dom, dom_clone); } #[test] fn it_can_deal_with_weird_whitespaces() { let html = indoc!( "
Text
< div> Text
Text
Text < /div>
Text
< div > Text < / div > " ); let dom = Dom::parse(html).unwrap(); assert_json_snapshot!(dom); }