2017-08-31 21:20:09 +08:00
|
|
|
extern crate env_logger;
|
2017-07-10 18:17:19 +08:00
|
|
|
extern crate mdbook;
|
|
|
|
extern crate tempdir;
|
|
|
|
|
2017-09-02 07:40:39 +08:00
|
|
|
mod dummy;
|
2017-07-10 18:17:19 +08:00
|
|
|
mod helpers;
|
2017-09-02 07:40:39 +08:00
|
|
|
|
|
|
|
use dummy::DummyBook;
|
|
|
|
use helpers::assert_contains_strings;
|
2017-07-10 18:17:19 +08:00
|
|
|
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-09-02 07:40:39 +08:00
|
|
|
let temp = 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-09-02 07:40:39 +08:00
|
|
|
let temp = 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-09-02 07:40:39 +08:00
|
|
|
let temp = 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![
|
2017-09-02 07:54:57 +08:00
|
|
|
r#"href="intro.html""#,
|
|
|
|
r#"href="./first/index.html""#,
|
|
|
|
r#"href="./first/nested.html""#,
|
|
|
|
r#"href="./second.html""#,
|
|
|
|
r#"href="./conclusion.html""#,
|
2017-07-10 18:17:19 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
let files_in_bottom_dir = vec!["index.html", "intro.html", "second.html", "conclusion.html"];
|
|
|
|
|
|
|
|
for filename in files_in_bottom_dir {
|
2017-09-02 07:40:39 +08:00
|
|
|
assert_contains_strings(dest.join(filename), &links);
|
2017-07-10 18:17:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_correct_cross_links_in_nested_dir() {
|
2017-09-02 07:40:39 +08:00
|
|
|
let temp = 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="../">"#,
|
2017-09-02 07:54:57 +08:00
|
|
|
r#"href="intro.html""#,
|
|
|
|
r#"href="./first/index.html""#,
|
|
|
|
r#"href="./first/nested.html""#,
|
|
|
|
r#"href="./second.html""#,
|
|
|
|
r#"href="./conclusion.html""#,
|
2017-07-10 18:17:19 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
let files_in_nested_dir = vec!["index.html", "nested.html"];
|
|
|
|
|
|
|
|
for filename in files_in_nested_dir {
|
2017-09-02 07:40:39 +08:00
|
|
|
assert_contains_strings(first.join(filename), &links);
|
2017-07-10 18:17:19 +08:00
|
|
|
}
|
2017-09-02 07:54:57 +08:00
|
|
|
|
|
|
|
assert_contains_strings(
|
|
|
|
first.join("index.html"),
|
|
|
|
&[
|
2017-08-31 21:20:09 +08:00
|
|
|
r##"href="./first/index.html#some-section" id="some-section""##,
|
2017-09-02 07:54:57 +08:00
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_contains_strings(
|
|
|
|
first.join("nested.html"),
|
|
|
|
&[
|
2017-08-31 21:20:09 +08:00
|
|
|
r##"href="./first/nested.html#some-section" id="some-section""##,
|
2017-09-02 07:54:57 +08:00
|
|
|
],
|
|
|
|
);
|
2017-07-10 18:17:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn rendered_code_has_playpen_stuff() {
|
2017-09-02 07:40:39 +08:00
|
|
|
let temp = 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""#];
|
|
|
|
|
2017-09-02 07:40:39 +08:00
|
|
|
assert_contains_strings(nested, &playpen_class);
|
2017-07-10 18:17:19 +08:00
|
|
|
|
|
|
|
let book_js = temp.path().join("book/book.js");
|
2017-09-02 07:40:39 +08:00
|
|
|
assert_contains_strings(book_js, &[".playpen"]);
|
2017-07-10 18:17:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn chapter_content_appears_in_rendered_document() {
|
2017-08-31 21:20:09 +08:00
|
|
|
env_logger::init().ok();
|
|
|
|
|
2017-07-10 18:17:19 +08:00
|
|
|
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-09-02 07:40:39 +08:00
|
|
|
let temp = 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);
|
2017-09-02 07:40:39 +08:00
|
|
|
assert_contains_strings(path, &[text]);
|
2017-07-10 18:17:19 +08:00
|
|
|
}
|
2017-09-02 07:40:39 +08:00
|
|
|
}
|
2017-08-31 21:20:09 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn chapter_1_file_not_created_if_summary_already_exists() {
|
|
|
|
let temp = DummyBook::default().build();
|
|
|
|
|
|
|
|
let src = temp.path().join("src");
|
|
|
|
let summary = src.join("SUMMARY.md");
|
|
|
|
let chapter_1 = src.join("chapter_1.md");
|
|
|
|
|
|
|
|
assert!(summary.exists());
|
|
|
|
assert!(!chapter_1.exists());
|
|
|
|
|
|
|
|
let mut md = MDBook::new(temp.path());
|
|
|
|
md.build().unwrap();
|
|
|
|
|
|
|
|
assert!(!chapter_1.exists());
|
|
|
|
}
|