From 0f397ebdb5480ad8cf225aa4a6bb37f7539f62d0 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 21 Apr 2025 18:51:59 -0700 Subject: [PATCH] Migrate rustdoc_include_hides_the_unspecified_part_of_the_file to BookTest --- tests/rendered_output.rs | 15 --------------- tests/testsuite/includes.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index 5cf91f66..591634db 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -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![ - "fn some_function() {", - "fn some_other_function() {", - ]; - - assert_contains_strings(nested, &text); -} - #[test] fn chapter_content_appears_in_rendered_document() { let content = vec![ diff --git a/tests/testsuite/includes.rs b/tests/testsuite/includes.rs index c7c28a1a..312caede 100644 --- a/tests/testsuite/includes.rs +++ b/tests/testsuite/includes.rs @@ -84,3 +84,29 @@ fn playground_include() { } "##]]); } + +// Checks the behavior of `{{#rustdoc_include}}`. +#[test] +fn rustdoc_include() { + BookTest::from_dir("includes/all_includes") + .check_main_file("book/rustdoc.html", + str![[r##" +

Rustdoc Includes

+

Rustdoc include adds the rest of the file as hidden

+
fn some_function() {
+    println!("some function");
+}
+
+fn main() {
+    some_function();
+}
+

Rustdoc include works with anchors too

+
fn some_other_function() {
+    println!("unused anchor");
+}
+
+fn main() {
+    some_other_function();
+}
+"##]]); +}