//! 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##"

Basic Includes

Sample

This is a sample include.

"##]], ) .check_main_file( "book/relative/includes.html", str![[r##"

Relative Includes

Sample

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##"

Include Anchors

#![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#" [TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started [TIMESTAMP] [ERROR] (mdbook_driver::builtin_preprocessors::links): Stack depth exceeded in recursive.md. Check for cyclic includes [TIMESTAMP] [INFO] (mdbook_driver::mdbook): Running the html backend [TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): 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##"

Playground Includes

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##"

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();
}
"##]]); }