From 3fce1151dd9a4448a3f9822f0ba43da7f428c302 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 22 Apr 2025 08:55:24 -0700 Subject: [PATCH] Migrate first_chapter_is_copied_as_index_even_if_not_first_elem to BookTest --- tests/rendered_output.rs | 15 -------------- tests/testsuite/rendering.rs | 20 +++++++++++++++++++ .../src/SUMMARY.md | 11 ++++++++++ 3 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 tests/testsuite/rendering/first_chapter_is_copied_as_index_even_if_not_first_elem/src/SUMMARY.md diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index c935fae0..d16c7a3f 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -271,21 +271,6 @@ fn example_book_can_build() { md.build().unwrap(); } -#[test] -fn first_chapter_is_copied_as_index_even_if_not_first_elem() { - let temp = DummyBook::new().build().unwrap(); - let mut cfg = Config::default(); - cfg.set("book.src", "index_html_test") - .expect("Couldn't set config.book.src to \"index_html_test\""); - let md = MDBook::load_with_config(temp.path(), cfg).unwrap(); - md.build().unwrap(); - - let root = temp.path().join("book"); - let chapter = fs::read_to_string(root.join("chapter_1.html")).expect("read chapter 1"); - let index = fs::read_to_string(root.join("index.html")).expect("read index"); - pretty_assertions::assert_eq!(chapter, index); -} - #[test] fn theme_dir_overrides_work_correctly() { let book_dir = dummy_book::new_copy_of_example_book().unwrap(); diff --git a/tests/testsuite/rendering.rs b/tests/testsuite/rendering.rs index 750e27dd..1d6cf476 100644 --- a/tests/testsuite/rendering.rs +++ b/tests/testsuite/rendering.rs @@ -21,3 +21,23 @@ fn edit_url_template_explicit_src() { title=\"Suggest an edit\" aria-label=\"Suggest an edit\">", ); } + +// Checks that index.html is generated correctly, even when the first few +// chapters are drafts. +#[test] +fn first_chapter_is_copied_as_index_even_if_not_first_elem() { + BookTest::from_dir("rendering/first_chapter_is_copied_as_index_even_if_not_first_elem") + // These two files should be equal. + .check_main_file( + "book/chapter_1.html", + str![[ + r##"

Chapter 1

"## + ]], + ) + .check_main_file( + "book/index.html", + str![[ + r##"

Chapter 1

"## + ]], + ); +} diff --git a/tests/testsuite/rendering/first_chapter_is_copied_as_index_even_if_not_first_elem/src/SUMMARY.md b/tests/testsuite/rendering/first_chapter_is_copied_as_index_even_if_not_first_elem/src/SUMMARY.md new file mode 100644 index 00000000..37bf68cd --- /dev/null +++ b/tests/testsuite/rendering/first_chapter_is_copied_as_index_even_if_not_first_elem/src/SUMMARY.md @@ -0,0 +1,11 @@ +# Summary + +--- + +- [None of these should be treated as the "index chapter"]() + +# Part 1 + +- [Not this either]() +- [Chapter 1](./chapter_1.md) +- [And not this]()