mdBook/tests/custom_preprocessors.rs

54 lines
1.2 KiB
Rust
Raw Permalink Normal View History

extern crate mdbook;
mod dummy_book;
use dummy_book::DummyBook;
use mdbook::preprocess::{CmdPreprocessor, Preprocessor};
2018-09-16 23:23:03 +08:00
use mdbook::MDBook;
fn example() -> CmdPreprocessor {
CmdPreprocessor::new("nop-preprocessor".to_string(), "cargo run --example nop-preprocessor --".to_string())
}
#[test]
fn example_supports_whatever() {
let cmd = example();
let got = cmd.supports_renderer("whatever");
assert_eq!(got, true);
}
#[test]
fn example_doesnt_support_not_supported() {
let cmd = example();
let got = cmd.supports_renderer("not-supported");
assert_eq!(got, false);
}
2018-09-16 23:23:03 +08:00
#[test]
fn ask_the_preprocessor_to_blow_up() {
let dummy_book = DummyBook::new();
let temp = dummy_book.build().unwrap();
let mut md = MDBook::load(temp.path()).unwrap();
2018-09-16 23:23:03 +08:00
md.with_preprecessor(example());
2018-09-16 23:28:01 +08:00
md.config.set("preprocessor.nop-preprocessor.blow-up", true).unwrap();
2018-09-16 23:23:03 +08:00
let got = md.build();
assert!(got.is_err());
}
#[test]
fn process_the_dummy_book() {
let dummy_book = DummyBook::new();
let temp = dummy_book.build().unwrap();
let mut md = MDBook::load(temp.path()).unwrap();
2018-09-16 23:23:03 +08:00
md.with_preprecessor(example());
md.build().unwrap();
}