2017-07-10 18:17:19 +08:00
|
|
|
extern crate mdbook;
|
|
|
|
extern crate tempdir;
|
|
|
|
|
|
|
|
mod helpers;
|
|
|
|
use mdbook::MDBook;
|
|
|
|
|
|
|
|
|
2017-08-02 22:29:28 +08:00
|
|
|
/// Make sure you can load the dummy book and build it without panicking.
|
2017-07-10 18:17:19 +08:00
|
|
|
#[test]
|
|
|
|
fn build_the_dummy_book() {
|
2017-08-02 22:29:28 +08:00
|
|
|
let temp = helpers::DummyBook::default().build();
|
2017-07-10 18:17:19 +08:00
|
|
|
let mut md = MDBook::new(temp.path());
|
|
|
|
|
|
|
|
md.build().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn by_default_mdbook_generates_rendered_content_in_the_book_directory() {
|
2017-08-02 22:29:28 +08:00
|
|
|
let temp = helpers::DummyBook::default().build();
|
2017-07-10 18:17:19 +08:00
|
|
|
let mut md = MDBook::new(temp.path());
|
|
|
|
|
|
|
|
assert!(!temp.path().join("book").exists());
|
|
|
|
md.build().unwrap();
|
|
|
|
|
|
|
|
assert!(temp.path().join("book").exists());
|
|
|
|
assert!(temp.path().join("book").join("index.html").exists());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn make_sure_bottom_level_files_contain_links_to_chapters() {
|
2017-08-02 22:29:28 +08:00
|
|
|
let temp = helpers::DummyBook::default().build();
|
2017-07-10 18:17:19 +08:00
|
|
|
let mut md = MDBook::new(temp.path());
|
|
|
|
md.build().unwrap();
|
|
|
|
|
|
|
|
let dest = temp.path().join("book");
|
|
|
|
let links = vec![
|
|
|
|
"intro.html",
|
|
|
|
"first/index.html",
|
|
|
|
"first/nested.html",
|
|
|
|
"second.html",
|
|
|
|
"conclusion.html",
|
|
|
|
];
|
|
|
|
|
|
|
|
let files_in_bottom_dir = vec!["index.html", "intro.html", "second.html", "conclusion.html"];
|
|
|
|
|
|
|
|
for filename in files_in_bottom_dir {
|
|
|
|
helpers::assert_contains_strings(dest.join(filename), &links);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_correct_cross_links_in_nested_dir() {
|
2017-08-02 22:29:28 +08:00
|
|
|
let temp = helpers::DummyBook::default().build();
|
2017-07-10 18:17:19 +08:00
|
|
|
let mut md = MDBook::new(temp.path());
|
|
|
|
md.build().unwrap();
|
|
|
|
|
|
|
|
let first = temp.path().join("book").join("first");
|
|
|
|
let links = vec![
|
|
|
|
r#"<base href="../">"#,
|
|
|
|
"intro.html",
|
|
|
|
"first/index.html",
|
|
|
|
"first/nested.html",
|
|
|
|
"second.html",
|
|
|
|
"conclusion.html",
|
|
|
|
];
|
|
|
|
|
|
|
|
let files_in_nested_dir = vec!["index.html", "nested.html"];
|
|
|
|
|
|
|
|
for filename in files_in_nested_dir {
|
|
|
|
helpers::assert_contains_strings(first.join(filename), &links);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn rendered_code_has_playpen_stuff() {
|
2017-08-02 22:29:28 +08:00
|
|
|
let temp = helpers::DummyBook::default().build();
|
2017-07-10 18:17:19 +08:00
|
|
|
let mut md = MDBook::new(temp.path());
|
|
|
|
md.build().unwrap();
|
|
|
|
|
|
|
|
let nested = temp.path().join("book/first/nested.html");
|
|
|
|
let playpen_class = vec![r#"class="playpen""#];
|
|
|
|
|
|
|
|
helpers::assert_contains_strings(nested, &playpen_class);
|
|
|
|
|
|
|
|
let book_js = temp.path().join("book/book.js");
|
|
|
|
helpers::assert_contains_strings(book_js, &[".playpen"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn chapter_content_appears_in_rendered_document() {
|
|
|
|
let content = vec![
|
|
|
|
("index.html", "Here's some interesting text"),
|
|
|
|
("second.html", "Second Chapter"),
|
|
|
|
("first/nested.html", "testable code"),
|
|
|
|
("first/index.html", "more text"),
|
|
|
|
("conclusion.html", "Conclusion"),
|
|
|
|
];
|
|
|
|
|
2017-08-02 22:29:28 +08:00
|
|
|
let temp = helpers::DummyBook::default().build();
|
2017-07-10 18:17:19 +08:00
|
|
|
let mut md = MDBook::new(temp.path());
|
|
|
|
md.build().unwrap();
|
|
|
|
|
|
|
|
let destination = temp.path().join("book");
|
|
|
|
|
|
|
|
for (filename, text) in content {
|
|
|
|
let path = destination.join(filename);
|
|
|
|
helpers::assert_contains_strings(path, &[text]);
|
|
|
|
}
|
|
|
|
}
|