use skyscraper::html;
#[test]
fn doctype_in_before_head_mode_is_ignored() {
let text = "<!DOCTYPE html><html><!DOCTYPE html><head></head><body></body></html>";
let document = html::parse(text).unwrap();
let output = document.to_string();
assert_eq!(
output.matches("<!DOCTYPE").count(),
1,
"Only one DOCTYPE should survive; got: {output:?}"
);
assert!(
output.contains("<head></head>"),
"Should contain <head></head>: {output:?}"
);
assert!(
output.contains("<body></body>"),
"Should contain <body></body>: {output:?}"
);
}
#[test]
fn html_start_tag_in_before_head_merges_attributes() {
let text = r#"<html><html lang="en"><head></head><body></body></html>"#;
let document = html::parse(text).unwrap();
let output = document.to_string();
assert_eq!(
output.matches("<html").count(),
1,
"Only one <html> should exist; got: {output:?}"
);
assert!(
output.contains(r#"lang="en""#),
"Should contain lang attribute: {output:?}"
);
}
#[test]
fn duplicate_html_start_tag_in_before_head_no_new_attrs() {
let text = "<html><html><head></head><body></body></html>";
let document = html::parse(text).unwrap();
let output = document.to_string();
assert_eq!(
output.matches("<html").count(),
1,
"Only one <html> should exist; got: {output:?}"
);
assert!(
output.contains("<head></head>"),
"Should contain <head>: {output:?}"
);
}
#[test]
fn unexpected_end_tag_in_before_head_mode_is_ignored() {
let text = "<html></div><head></head><body></body></html>";
let document = html::parse(text).unwrap();
let output = document.to_string();
assert!(
!output.contains("</div>"),
"Stray </div> should not appear: {output:?}"
);
assert!(
output.contains("<head></head>"),
"Should contain <head></head>: {output:?}"
);
}
#[test]
fn multiple_unexpected_end_tags_in_before_head_mode_are_ignored() {
let text = "<html></span></footer></section><head></head><body></body></html>";
let document = html::parse(text).unwrap();
let output = document.to_string();
assert!(
!output.contains("</span>")
&& !output.contains("</footer>")
&& !output.contains("</section>"),
"No stray end tags should appear: {output:?}"
);
assert!(
output.contains("<head></head>"),
"Should contain <head></head>: {output:?}"
);
}