diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index f648b72d..0a151a54 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -364,24 +364,6 @@ fn able_to_include_playground_files_in_chapters() { assert_doesnt_contain_strings(&second, &["{{#playground example.rs}}"]); } -/// This makes sure you can include a Rust file with `{{#include ../SUMMARY.md}}`. -#[test] -fn able_to_include_files_in_chapters() { - let temp = DummyBook::new().build().unwrap(); - let md = MDBook::load(temp.path()).unwrap(); - md.build().unwrap(); - - let includes = temp.path().join("book/first/includes.html"); - - let summary_strings = &[ - r##"
This is a sample include.
+"##]], + ) + .check_main_file( + "book/relative/includes.html", + str![[r##" +This is a sample include.
+"##]], + ); +} diff --git a/tests/testsuite/includes/all_includes/book.toml b/tests/testsuite/includes/all_includes/book.toml new file mode 100644 index 00000000..622694be --- /dev/null +++ b/tests/testsuite/includes/all_includes/book.toml @@ -0,0 +1,6 @@ +[book] +authors = ["Eric Huss"] +language = "en" +multilingual = false +src = "src" +title = "all_includes" diff --git a/tests/testsuite/includes/all_includes/src/SUMMARY.md b/tests/testsuite/includes/all_includes/src/SUMMARY.md new file mode 100644 index 00000000..25a9a15f --- /dev/null +++ b/tests/testsuite/includes/all_includes/src/SUMMARY.md @@ -0,0 +1,8 @@ +# Summary + +- [Basic Includes](./includes.md) + - [Relative Includes](./relative/includes.md) +- [Recursive Includes](./recursive.md) +- [Include Anchors](./anchors.md) +- [Rustdoc Includes](./rustdoc.md) +- [Playground Includes](./playground.md) diff --git a/tests/testsuite/includes/all_includes/src/anchors.md b/tests/testsuite/includes/all_includes/src/anchors.md new file mode 100644 index 00000000..0ffbc788 --- /dev/null +++ b/tests/testsuite/includes/all_includes/src/anchors.md @@ -0,0 +1,5 @@ +# Include Anchors + +```rust +{{#include nested-test-with-anchors.rs:myanchor}} +``` diff --git a/tests/testsuite/includes/all_includes/src/example.rs b/tests/testsuite/includes/all_includes/src/example.rs new file mode 100644 index 00000000..6b49705c --- /dev/null +++ b/tests/testsuite/includes/all_includes/src/example.rs @@ -0,0 +1,6 @@ +fn main() { + println!("Hello World!"); +# +# // You can even hide lines! :D +# println!("I am hidden! Expand the code snippet to see me"); +} diff --git a/tests/testsuite/includes/all_includes/src/includes.md b/tests/testsuite/includes/all_includes/src/includes.md new file mode 100644 index 00000000..539aa939 --- /dev/null +++ b/tests/testsuite/includes/all_includes/src/includes.md @@ -0,0 +1,4 @@ +# Basic Includes + +{{#include sample.md}} + diff --git a/tests/testsuite/includes/all_includes/src/nested-test-with-anchors.rs b/tests/testsuite/includes/all_includes/src/nested-test-with-anchors.rs new file mode 100644 index 00000000..93c61dd4 --- /dev/null +++ b/tests/testsuite/includes/all_includes/src/nested-test-with-anchors.rs @@ -0,0 +1,6 @@ +// This is a test of includes with anchors. + +// ANCHOR: myanchor +// ANCHOR: unendinganchor +let x = 1; +// ANCHOR_END: myanchor diff --git a/tests/testsuite/includes/all_includes/src/partially-included-test-with-anchors.rs b/tests/testsuite/includes/all_includes/src/partially-included-test-with-anchors.rs new file mode 100644 index 00000000..8e732d0b --- /dev/null +++ b/tests/testsuite/includes/all_includes/src/partially-included-test-with-anchors.rs @@ -0,0 +1,11 @@ +fn some_other_function() { + // ANCHOR: unused-anchor-that-should-be-stripped + println!("unused anchor"); + // ANCHOR_END: unused-anchor-that-should-be-stripped +} + +// ANCHOR: rustdoc-include-anchor +fn main() { + some_other_function(); +} +// ANCHOR_END: rustdoc-include-anchor diff --git a/tests/testsuite/includes/all_includes/src/partially-included-test.rs b/tests/testsuite/includes/all_includes/src/partially-included-test.rs new file mode 100644 index 00000000..915651ea --- /dev/null +++ b/tests/testsuite/includes/all_includes/src/partially-included-test.rs @@ -0,0 +1,7 @@ +fn some_function() { + println!("some function"); +} + +fn main() { + some_function(); +} diff --git a/tests/testsuite/includes/all_includes/src/playground.md b/tests/testsuite/includes/all_includes/src/playground.md new file mode 100644 index 00000000..9c20530c --- /dev/null +++ b/tests/testsuite/includes/all_includes/src/playground.md @@ -0,0 +1,3 @@ +# Playground Includes + +{{#playground example.rs}} diff --git a/tests/testsuite/includes/all_includes/src/recursive.md b/tests/testsuite/includes/all_includes/src/recursive.md new file mode 100644 index 00000000..cb82a52f --- /dev/null +++ b/tests/testsuite/includes/all_includes/src/recursive.md @@ -0,0 +1,2 @@ +Around the world, around the world +{{#include recursive.md}} diff --git a/tests/testsuite/includes/all_includes/src/relative/includes.md b/tests/testsuite/includes/all_includes/src/relative/includes.md new file mode 100644 index 00000000..f0a6fce6 --- /dev/null +++ b/tests/testsuite/includes/all_includes/src/relative/includes.md @@ -0,0 +1,3 @@ +# Relative Includes + +{{#include ../sample.md}} diff --git a/tests/testsuite/includes/all_includes/src/rustdoc.md b/tests/testsuite/includes/all_includes/src/rustdoc.md new file mode 100644 index 00000000..8a342d90 --- /dev/null +++ b/tests/testsuite/includes/all_includes/src/rustdoc.md @@ -0,0 +1,13 @@ +# Rustdoc Includes + +## Rustdoc include adds the rest of the file as hidden + +```rust +{{#rustdoc_include partially-included-test.rs:5:7}} +``` + +## Rustdoc include works with anchors too + +```rust +{{#rustdoc_include partially-included-test-with-anchors.rs:rustdoc-include-anchor}} +``` diff --git a/tests/testsuite/includes/all_includes/src/sample.md b/tests/testsuite/includes/all_includes/src/sample.md new file mode 100644 index 00000000..91071ef8 --- /dev/null +++ b/tests/testsuite/includes/all_includes/src/sample.md @@ -0,0 +1,3 @@ +## Sample + +This is a sample include. diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index c8630267..d273b992 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -5,6 +5,7 @@ mod book_test; mod build; mod cli; +mod includes; mod prelude { pub use crate::book_test::BookTest;