mdBook/tests/jsonconfig.rs
Michal Budzynski b1ca9cf5b5 HtmlConfig is no longer optional
`HtmlConfig` was both guaranteed to exist within `BookConfig`
and `expect`ed in few places.
This simplifies the API a little by representing the fact that
`HtmlConfig` is currently mandatory for proper mdBook binary operation.
2017-06-27 14:01:33 +02:00

88 lines
2.4 KiB
Rust

extern crate mdbook;
use mdbook::config::BookConfig;
use mdbook::config::jsonconfig::JsonConfig;
use std::path::PathBuf;
// Tests that the `src` key is correctly parsed in the JSON config
#[test]
fn from_json_source() {
let json = r#"{
"src": "source"
}"#;
let parsed = JsonConfig::from_json(json).expect("This should parse");
let config = BookConfig::from_jsonconfig("root", parsed);
assert_eq!(config.get_source(), PathBuf::from("root/source"));
}
// Tests that the `title` key is correctly parsed in the JSON config
#[test]
fn from_json_title() {
let json = r#"{
"title": "Some title"
}"#;
let parsed = JsonConfig::from_json(json).expect("This should parse");
let config = BookConfig::from_jsonconfig("root", parsed);
assert_eq!(config.get_title(), "Some title");
}
// Tests that the `description` key is correctly parsed in the JSON config
#[test]
fn from_json_description() {
let json = r#"{
"description": "This is a description"
}"#;
let parsed = JsonConfig::from_json(json).expect("This should parse");
let config = BookConfig::from_jsonconfig("root", parsed);
assert_eq!(config.get_description(), "This is a description");
}
// Tests that the `author` key is correctly parsed in the JSON config
#[test]
fn from_json_author() {
let json = r#"{
"author": "John Doe"
}"#;
let parsed = JsonConfig::from_json(json).expect("This should parse");
let config = BookConfig::from_jsonconfig("root", parsed);
assert_eq!(config.get_authors(), &[String::from("John Doe")]);
}
// Tests that the `dest` key is correctly parsed in the JSON config
#[test]
fn from_json_destination() {
let json = r#"{
"dest": "htmlbook"
}"#;
let parsed = JsonConfig::from_json(json).expect("This should parse");
let config = BookConfig::from_jsonconfig("root", parsed);
let htmlconfig = config.get_html_config();
assert_eq!(htmlconfig.get_destination(), PathBuf::from("root/htmlbook"));
}
// Tests that the `theme_path` key is correctly parsed in the JSON config
#[test]
fn from_json_output_html_theme() {
let json = r#"{
"theme_path": "theme"
}"#;
let parsed = JsonConfig::from_json(json).expect("This should parse");
let config = BookConfig::from_jsonconfig("root", parsed);
let htmlconfig = config.get_html_config();
assert_eq!(htmlconfig.get_theme(), &PathBuf::from("root/theme"));
}