Skip to content

Commit 8ce12d8

Browse files
Merge pull request #676 from jyn514/html-tests
Add tests for HTML parsing
2 parents b6f81fa + b3b90f1 commit 8ce12d8

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

src/utils/html.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,28 @@ fn extract_class(node: &Handle) -> String {
7272
_ => String::new()
7373
}
7474
}
75+
76+
#[cfg(test)]
77+
mod test {
78+
#[test]
79+
fn small_html() {
80+
let (head, body, class) = super::extract_head_and_body(
81+
r#"<head><meta name="generator" content="rustdoc"></head><body class="rustdoc struct"><p>hello</p>"#
82+
).unwrap();
83+
assert_eq!(head, r#"<meta name="generator" content="rustdoc">"#);
84+
assert_eq!(body, "<p>hello</p>");
85+
assert_eq!(class, "rustdoc struct");
86+
}
87+
88+
// more of an integration test
89+
#[test]
90+
fn parse_regex_html() {
91+
let original = std::fs::read_to_string("benches/struct.CaptureMatches.html").unwrap();
92+
let expected_head = std::fs::read_to_string("tests/regex/head.html").unwrap();
93+
let expected_body = std::fs::read_to_string("tests/regex/body.html").unwrap();
94+
let (head, body, class) = super::extract_head_and_body(&original).unwrap();
95+
assert_eq!(head, expected_head.trim());
96+
assert_eq!(&body, &expected_body.trim());
97+
assert_eq!(class, "rustdoc struct");
98+
}
99+
}

0 commit comments

Comments
 (0)