Migrate able_to_include_files_in_chapters to BookTest
This commit is contained in:
parent
dd778d50f9
commit
03470a7531
16 changed files with 103 additions and 18 deletions
|
|
@ -364,24 +364,6 @@ fn able_to_include_playground_files_in_chapters() {
|
||||||
assert_doesnt_contain_strings(&second, &["{{#playground example.rs}}"]);
|
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##"<h1 id="summary"><a class="header" href="#summary">Summary</a></h1>"##,
|
|
||||||
">First Chapter</a>",
|
|
||||||
];
|
|
||||||
assert_contains_strings(&includes, summary_strings);
|
|
||||||
|
|
||||||
assert_doesnt_contain_strings(&includes, &["{{#include ../SUMMARY.md::}}"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ensure cyclic includes are capped so that no exceptions occur
|
/// Ensure cyclic includes are capped so that no exceptions occur
|
||||||
#[test]
|
#[test]
|
||||||
fn recursive_includes_are_capped() {
|
fn recursive_includes_are_capped() {
|
||||||
|
|
|
||||||
25
tests/testsuite/includes.rs
Normal file
25
tests/testsuite/includes.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
//! Tests for include preprocessor.
|
||||||
|
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
// Basic test for #include.
|
||||||
|
#[test]
|
||||||
|
fn include() {
|
||||||
|
BookTest::from_dir("includes/all_includes")
|
||||||
|
.check_main_file(
|
||||||
|
"book/includes.html",
|
||||||
|
str![[r##"
|
||||||
|
<h1 id="basic-includes"><a class="header" href="#basic-includes">Basic Includes</a></h1>
|
||||||
|
<h2 id="sample"><a class="header" href="#sample">Sample</a></h2>
|
||||||
|
<p>This is a sample include.</p>
|
||||||
|
"##]],
|
||||||
|
)
|
||||||
|
.check_main_file(
|
||||||
|
"book/relative/includes.html",
|
||||||
|
str![[r##"
|
||||||
|
<h1 id="relative-includes"><a class="header" href="#relative-includes">Relative Includes</a></h1>
|
||||||
|
<h2 id="sample"><a class="header" href="#sample">Sample</a></h2>
|
||||||
|
<p>This is a sample include.</p>
|
||||||
|
"##]],
|
||||||
|
);
|
||||||
|
}
|
||||||
6
tests/testsuite/includes/all_includes/book.toml
Normal file
6
tests/testsuite/includes/all_includes/book.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
[book]
|
||||||
|
authors = ["Eric Huss"]
|
||||||
|
language = "en"
|
||||||
|
multilingual = false
|
||||||
|
src = "src"
|
||||||
|
title = "all_includes"
|
||||||
8
tests/testsuite/includes/all_includes/src/SUMMARY.md
Normal file
8
tests/testsuite/includes/all_includes/src/SUMMARY.md
Normal file
|
|
@ -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)
|
||||||
5
tests/testsuite/includes/all_includes/src/anchors.md
Normal file
5
tests/testsuite/includes/all_includes/src/anchors.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Include Anchors
|
||||||
|
|
||||||
|
```rust
|
||||||
|
{{#include nested-test-with-anchors.rs:myanchor}}
|
||||||
|
```
|
||||||
6
tests/testsuite/includes/all_includes/src/example.rs
Normal file
6
tests/testsuite/includes/all_includes/src/example.rs
Normal file
|
|
@ -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");
|
||||||
|
}
|
||||||
4
tests/testsuite/includes/all_includes/src/includes.md
Normal file
4
tests/testsuite/includes/all_includes/src/includes.md
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Basic Includes
|
||||||
|
|
||||||
|
{{#include sample.md}}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
// This is a test of includes with anchors.
|
||||||
|
|
||||||
|
// ANCHOR: myanchor
|
||||||
|
// ANCHOR: unendinganchor
|
||||||
|
let x = 1;
|
||||||
|
// ANCHOR_END: myanchor
|
||||||
|
|
@ -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
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
fn some_function() {
|
||||||
|
println!("some function");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
some_function();
|
||||||
|
}
|
||||||
3
tests/testsuite/includes/all_includes/src/playground.md
Normal file
3
tests/testsuite/includes/all_includes/src/playground.md
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Playground Includes
|
||||||
|
|
||||||
|
{{#playground example.rs}}
|
||||||
2
tests/testsuite/includes/all_includes/src/recursive.md
Normal file
2
tests/testsuite/includes/all_includes/src/recursive.md
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
Around the world, around the world
|
||||||
|
{{#include recursive.md}}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Relative Includes
|
||||||
|
|
||||||
|
{{#include ../sample.md}}
|
||||||
13
tests/testsuite/includes/all_includes/src/rustdoc.md
Normal file
13
tests/testsuite/includes/all_includes/src/rustdoc.md
Normal file
|
|
@ -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}}
|
||||||
|
```
|
||||||
3
tests/testsuite/includes/all_includes/src/sample.md
Normal file
3
tests/testsuite/includes/all_includes/src/sample.md
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
## Sample
|
||||||
|
|
||||||
|
This is a sample include.
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
mod book_test;
|
mod book_test;
|
||||||
mod build;
|
mod build;
|
||||||
mod cli;
|
mod cli;
|
||||||
|
mod includes;
|
||||||
|
|
||||||
mod prelude {
|
mod prelude {
|
||||||
pub use crate::book_test::BookTest;
|
pub use crate::book_test::BookTest;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue