//! 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##"
This is a sample include.
"##]], ) .check_main_file( "book/relative/includes.html", str![[r##"This is a sample include.
"##]], ); } // Checks for anchored includes. #[test] fn anchored_include() { BookTest::from_dir("includes/all_includes").check_main_file( "book/anchors.html", str![[r##"#![allow(unused)]
fn main() {
let x = 1;
}
"##]],
);
}
// Checks behavior of recursive include.
#[test]
fn recursive_include() {
BookTest::from_dir("includes/all_includes")
.run("build", |cmd| {
cmd.expect_stderr(str![[r#"
INFO Book building has started
ERROR Stack depth exceeded in recursive.md. Check for cyclic includes
INFO Running the html backend
INFO HTML book written to `[ROOT]/book`
"#]]);
})
.check_main_file(
"book/recursive.html",
str![[r#"
Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world Around the world, around the world
"#]], ); } // Checks the behavior of `{{#playground}}` include. #[test] fn playground_include() { BookTest::from_dir("includes/all_includes") .check_main_file("book/playground.html", str![[r##"fn main() {
println!("Hello World!");
// You can even hide lines! :D
println!("I am hidden! Expand the code snippet to see me");
}
"##]]);
}
// Checks the behavior of `{{#rustdoc_include}}`.
#[test]
fn rustdoc_include() {
BookTest::from_dir("includes/all_includes")
.check_main_file("book/rustdoc.html",
str![[r##"
fn some_function() {
println!("some function");
}
fn main() {
some_function();
}
fn some_other_function() {
println!("unused anchor");
}
fn main() {
some_other_function();
}
"##]]);
}