Skip to content

Commit 009ebdc

Browse files
committed
Add tests for IndexPreprocessor
1 parent 92487a3 commit 009ebdc

File tree

6 files changed

+41
-0
lines changed

6 files changed

+41
-0
lines changed

tests/dummy_book/src2/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Root README

tests/dummy_book/src2/SUMMARY.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This dummy book is for testing the conversion of README.md to index.html by IndexPreprocessor
2+
3+
[Root README](README.md)
4+
5+
- [1st README](first/README.md)
6+
- [2nd README](second/README.md)
7+
- [2nd index](second/index.md)

tests/dummy_book/src2/first/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# First README
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Second README

tests/dummy_book/src2/second/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Second index

tests/rendered_output.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,36 @@ fn book_with_a_reserved_filename_does_not_build() {
340340
assert!(got.is_err());
341341
}
342342

343+
#[test]
344+
fn by_default_mdbook_use_index_preprocessor_to_convert_readme_to_index() {
345+
let temp = DummyBook::new().build().unwrap();
346+
let mut cfg = Config::default();
347+
cfg.set("book.src", "src2").expect("Couldn't set config.book.src to \"src2\".");
348+
let md = MDBook::load_with_config(temp.path(), cfg).unwrap();
349+
md.build().unwrap();
350+
351+
let first_index = temp.path()
352+
.join("book")
353+
.join("first")
354+
.join("index.html");
355+
let expected_strings = vec![
356+
r#"href="first/index.html""#,
357+
r#"href="second/index.html""#,
358+
"First README",
359+
];
360+
assert_contains_strings(&first_index, &expected_strings);
361+
assert_doesnt_contain_strings(&first_index, &vec!["README.html"]);
362+
363+
let second_index = temp.path()
364+
.join("book")
365+
.join("second")
366+
.join("index.html");
367+
let unexpected_strings = vec![
368+
"Second README",
369+
];
370+
assert_doesnt_contain_strings(&second_index, &unexpected_strings);
371+
}
372+
343373
#[cfg(feature = "search")]
344374
mod search {
345375
extern crate serde_json;

0 commit comments

Comments
 (0)