use skyscraper::html;
#[test]
fn comment_after_body_inserted_in_html_element() {
let text = "<html><head></head><body></body><!-- after body --></html>";
let document = html::parse(text).unwrap();
let output = document.to_string();
assert!(
output.contains("<!-- after body -->"),
"Should contain the comment: {output:?}"
);
assert!(
output.contains("</body><!-- after body -->"),
"Comment should appear after </body>: {output:?}"
);
}
#[test]
fn multiple_comments_after_body() {
let text = "<html><head></head><body></body><!-- one --><!-- two --></html>";
let document = html::parse(text).unwrap();
let output = document.to_string();
assert!(
output.contains("<!-- one -->"),
"Should contain first comment: {output:?}"
);
assert!(
output.contains("<!-- two -->"),
"Should contain second comment: {output:?}"
);
}
#[test]
fn doctype_after_body_is_ignored() {
let text = "<!DOCTYPE html><html><head></head><body></body><!DOCTYPE html></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:?}"
);
}
#[test]
fn comment_after_after_body_inserted_in_document() {
let text = "<html><head></head><body></body></html><!-- after html -->";
let document = html::parse(text).unwrap();
let output = document.to_string();
assert!(
output.contains("<!-- after html -->"),
"Should contain the comment: {output:?}"
);
assert!(
output.contains("</html><!-- after html -->"),
"Comment should appear after </html>: {output:?}"
);
}
#[test]
fn multiple_comments_after_after_body() {
let text = "<html><head></head><body></body></html><!-- a --><!-- b -->";
let document = html::parse(text).unwrap();
let output = document.to_string();
assert!(
output.contains("<!-- a -->"),
"Should contain first comment: {output:?}"
);
assert!(
output.contains("<!-- b -->"),
"Should contain second comment: {output:?}"
);
}