Migrate rustdoc_include_hides_the_unspecified_part_of_the_file to BookTest

This commit is contained in:
Eric Huss 2025-04-21 18:51:59 -07:00
parent 342b6ee7b5
commit 0f397ebdb5
2 changed files with 26 additions and 15 deletions

View file

@ -127,21 +127,6 @@ fn rendered_code_does_not_have_playground_stuff_in_html_when_disabled_in_config(
assert_doesnt_contain_strings(nested, &playground_class);
}
#[test]
fn rustdoc_include_hides_the_unspecified_part_of_the_file() {
let temp = DummyBook::new().build().unwrap();
let md = MDBook::load(temp.path()).unwrap();
md.build().unwrap();
let nested = temp.path().join("book/first/nested.html");
let text = vec![
"<span class=\"boring\">fn some_function() {",
"<span class=\"boring\">fn some_other_function() {",
];
assert_contains_strings(nested, &text);
}
#[test]
fn chapter_content_appears_in_rendered_document() {
let content = vec![

View file

@ -84,3 +84,29 @@ fn playground_include() {
</span>}</code></pre></pre>
"##]]);
}
// Checks the behavior of `{{#rustdoc_include}}`.
#[test]
fn rustdoc_include() {
BookTest::from_dir("includes/all_includes")
.check_main_file("book/rustdoc.html",
str![[r##"
<h1 id="rustdoc-includes"><a class="header" href="#rustdoc-includes">Rustdoc Includes</a></h1>
<h2 id="rustdoc-include-adds-the-rest-of-the-file-as-hidden"><a class="header" href="#rustdoc-include-adds-the-rest-of-the-file-as-hidden">Rustdoc include adds the rest of the file as hidden</a></h2>
<pre><pre class="playground"><code class="language-rust"><span class="boring">fn some_function() {
</span><span class="boring"> println!("some function");
</span><span class="boring">}
</span><span class="boring">
</span>fn main() {
some_function();
}</code></pre></pre>
<h2 id="rustdoc-include-works-with-anchors-too"><a class="header" href="#rustdoc-include-works-with-anchors-too">Rustdoc include works with anchors too</a></h2>
<pre><pre class="playground"><code class="language-rust"><span class="boring">fn some_other_function() {
</span><span class="boring"> println!("unused anchor");
</span><span class="boring">}
</span><span class="boring">
</span>fn main() {
some_other_function();
}</code></pre></pre>
"##]]);
}