Skip to content

Commit

Permalink
Add tests for IndexPreprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed May 3, 2018
1 parent 92487a3 commit 009ebdc
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/dummy_book/src2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Root README
7 changes: 7 additions & 0 deletions tests/dummy_book/src2/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This dummy book is for testing the conversion of README.md to index.html by IndexPreprocessor

[Root README](README.md)

- [1st README](first/README.md)
- [2nd README](second/README.md)
- [2nd index](second/index.md)
1 change: 1 addition & 0 deletions tests/dummy_book/src2/first/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# First README
1 change: 1 addition & 0 deletions tests/dummy_book/src2/second/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Second README
1 change: 1 addition & 0 deletions tests/dummy_book/src2/second/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Second index
30 changes: 30 additions & 0 deletions tests/rendered_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,36 @@ fn book_with_a_reserved_filename_does_not_build() {
assert!(got.is_err());
}

#[test]
fn by_default_mdbook_use_index_preprocessor_to_convert_readme_to_index() {
let temp = DummyBook::new().build().unwrap();
let mut cfg = Config::default();
cfg.set("book.src", "src2").expect("Couldn't set config.book.src to \"src2\".");
let md = MDBook::load_with_config(temp.path(), cfg).unwrap();
md.build().unwrap();

let first_index = temp.path()
.join("book")
.join("first")
.join("index.html");
let expected_strings = vec![
r#"href="first/index.html""#,
r#"href="second/index.html""#,
"First README",
];
assert_contains_strings(&first_index, &expected_strings);
assert_doesnt_contain_strings(&first_index, &vec!["README.html"]);

let second_index = temp.path()
.join("book")
.join("second")
.join("index.html");
let unexpected_strings = vec![
"Second README",
];
assert_doesnt_contain_strings(&second_index, &unexpected_strings);
}

#[cfg(feature = "search")]
mod search {
extern crate serde_json;
Expand Down

0 comments on commit 009ebdc

Please sign in to comment.