Migrate by_default_mdbook_use_index_preprocessor_to_convert_readme_to_index to BookTest
This commit is contained in:
parent
0f397ebdb5
commit
c6d9f15cba
8 changed files with 50 additions and 20 deletions
|
|
@ -328,26 +328,6 @@ fn example_book_can_build() {
|
||||||
md.build().unwrap();
|
md.build().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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("toc.js");
|
|
||||||
let expected_strings = vec![
|
|
||||||
r#"href="first/index.html""#,
|
|
||||||
r#"href="second/index.html""#,
|
|
||||||
"1st README",
|
|
||||||
"2nd README",
|
|
||||||
];
|
|
||||||
assert_contains_strings(&first_index, &expected_strings);
|
|
||||||
assert_doesnt_contain_strings(&first_index, &["README.html", "Second README"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn first_chapter_is_copied_as_index_even_if_not_first_elem() {
|
fn first_chapter_is_copied_as_index_even_if_not_first_elem() {
|
||||||
let temp = DummyBook::new().build().unwrap();
|
let temp = DummyBook::new().build().unwrap();
|
||||||
|
|
|
||||||
38
tests/testsuite/index.rs
Normal file
38
tests/testsuite/index.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
//! Tests for the index preprocessor.
|
||||||
|
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
// Checks basic README to index.html conversion.
|
||||||
|
#[test]
|
||||||
|
fn readme_to_index() {
|
||||||
|
let mut test = BookTest::from_dir("index/basic_readme");
|
||||||
|
test.check_main_file(
|
||||||
|
"book/index.html",
|
||||||
|
str![[r##"<h1 id="intro"><a class="header" href="#intro">Intro</a></h1>"##]],
|
||||||
|
)
|
||||||
|
.check_main_file(
|
||||||
|
"book/first/index.html",
|
||||||
|
str![[r##"<h1 id="first"><a class="header" href="#first">First</a></h1>"##]],
|
||||||
|
)
|
||||||
|
.check_main_file(
|
||||||
|
"book/second/index.html",
|
||||||
|
str![[r##"<h1 id="second"><a class="header" href="#second">Second</a></h1>"##]],
|
||||||
|
)
|
||||||
|
.check_toc_js(str![[r#"
|
||||||
|
<ol class="chapter">
|
||||||
|
<li class="chapter-item expanded affix ">
|
||||||
|
<a href="index.html">Intro</a>
|
||||||
|
</li>
|
||||||
|
<li class="chapter-item expanded ">
|
||||||
|
<a href="first/index.html">
|
||||||
|
<strong aria-hidden="true">1.</strong> First</a>
|
||||||
|
</li>
|
||||||
|
<li class="chapter-item expanded ">
|
||||||
|
<a href="second/index.html">
|
||||||
|
<strong aria-hidden="true">2.</strong> Second</a>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
"#]]);
|
||||||
|
assert!(test.dir.join("book/index.html").exists());
|
||||||
|
assert!(!test.dir.join("book/README.html").exists());
|
||||||
|
}
|
||||||
2
tests/testsuite/index/basic_readme/book.toml
Normal file
2
tests/testsuite/index/basic_readme/book.toml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
[book]
|
||||||
|
title = "basic_readme"
|
||||||
1
tests/testsuite/index/basic_readme/src/README.md
Normal file
1
tests/testsuite/index/basic_readme/src/README.md
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
# Intro
|
||||||
6
tests/testsuite/index/basic_readme/src/SUMMARY.md
Normal file
6
tests/testsuite/index/basic_readme/src/SUMMARY.md
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
# Summary
|
||||||
|
|
||||||
|
[Intro](./README.md)
|
||||||
|
|
||||||
|
- [First](first/README)
|
||||||
|
- [Second](second/Readme.md)
|
||||||
1
tests/testsuite/index/basic_readme/src/first/README
Normal file
1
tests/testsuite/index/basic_readme/src/first/README
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
# First
|
||||||
1
tests/testsuite/index/basic_readme/src/second/Readme.md
Normal file
1
tests/testsuite/index/basic_readme/src/second/Readme.md
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
# Second
|
||||||
|
|
@ -6,6 +6,7 @@ mod book_test;
|
||||||
mod build;
|
mod build;
|
||||||
mod cli;
|
mod cli;
|
||||||
mod includes;
|
mod includes;
|
||||||
|
mod index;
|
||||||
|
|
||||||
mod prelude {
|
mod prelude {
|
||||||
pub use crate::book_test::BookTest;
|
pub use crate::book_test::BookTest;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue