From a2385982f6683398a50ea5251d2abaa20ef0cbcf Mon Sep 17 00:00:00 2001 From: Peter Sooley Date: Wed, 5 Jan 2022 07:07:02 -0500 Subject: [PATCH] add test for logical vs source paths --- tests/rendered_output.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index 5ec6e64b..52b6112c 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -382,6 +382,38 @@ fn able_to_include_files_in_chapters() { assert_doesnt_contain_strings(&includes, &["{{#include ../SUMMARY.md::}}"]); } +/// This makes sure chapter::path is a logical value and chapter::source_path has the real path +/// on the file system which is used for partial includes. +#[test] +fn able_to_include_files_in_chapters_regardless_of_logical_path() { + let temp = DummyBook::new().build().unwrap(); + let mut md = MDBook::load(temp.path()).unwrap(); + fn bad_path(sec: &mut mdbook::BookItem) { + match sec { + mdbook::BookItem::Chapter(c) => { + if let Some(ref mut p) = c.path { + p.set_extension(""); + p.push("oops.md"); + } + c.sub_items.iter_mut().for_each(bad_path); + } + _ => {} + } + } + md.book.sections.iter_mut().for_each(bad_path); + md.build().unwrap(); + + let includes = temp.path().join("book/first/includes.html"); + + let summary_strings = &[ + r##"

Summary

"##, + ">First Chapter", + ]; + assert_contains_strings(&includes, summary_strings); + + assert_doesnt_contain_strings(&includes, &["{{#include ../SUMMARY.md::}}"]); +} + /// Ensure cyclic includes are capped so that no exceptions occur #[test] fn recursive_includes_are_capped() {