2017-05-19 06:56:37 +08:00
|
|
|
extern crate mdbook;
|
|
|
|
use mdbook::config::BookConfig;
|
|
|
|
use mdbook::config::jsonconfig::JsonConfig;
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2017-06-01 13:28:08 +08:00
|
|
|
// Tests that the `src` key is correctly parsed in the JSON config
|
2017-05-19 06:56:37 +08:00
|
|
|
#[test]
|
|
|
|
fn from_json_source() {
|
|
|
|
let json = r#"{
|
|
|
|
"src": "source"
|
|
|
|
}"#;
|
|
|
|
|
2017-06-27 15:08:58 +08:00
|
|
|
let parsed = JsonConfig::from_json(json).expect("This should parse");
|
2017-05-19 06:56:37 +08:00
|
|
|
let config = BookConfig::from_jsonconfig("root", parsed);
|
|
|
|
|
|
|
|
assert_eq!(config.get_source(), PathBuf::from("root/source"));
|
|
|
|
}
|
|
|
|
|
2017-06-01 13:28:08 +08:00
|
|
|
// Tests that the `title` key is correctly parsed in the JSON config
|
2017-05-19 06:56:37 +08:00
|
|
|
#[test]
|
|
|
|
fn from_json_title() {
|
|
|
|
let json = r#"{
|
|
|
|
"title": "Some title"
|
|
|
|
}"#;
|
|
|
|
|
2017-06-27 15:08:58 +08:00
|
|
|
let parsed = JsonConfig::from_json(json).expect("This should parse");
|
2017-05-19 06:56:37 +08:00
|
|
|
let config = BookConfig::from_jsonconfig("root", parsed);
|
|
|
|
|
|
|
|
assert_eq!(config.get_title(), "Some title");
|
|
|
|
}
|
|
|
|
|
2017-06-01 13:28:08 +08:00
|
|
|
// Tests that the `description` key is correctly parsed in the JSON config
|
2017-05-19 06:56:37 +08:00
|
|
|
#[test]
|
|
|
|
fn from_json_description() {
|
|
|
|
let json = r#"{
|
|
|
|
"description": "This is a description"
|
|
|
|
}"#;
|
|
|
|
|
2017-06-27 15:08:58 +08:00
|
|
|
let parsed = JsonConfig::from_json(json).expect("This should parse");
|
2017-05-19 06:56:37 +08:00
|
|
|
let config = BookConfig::from_jsonconfig("root", parsed);
|
|
|
|
|
|
|
|
assert_eq!(config.get_description(), "This is a description");
|
|
|
|
}
|
|
|
|
|
2017-06-01 13:28:08 +08:00
|
|
|
// Tests that the `author` key is correctly parsed in the JSON config
|
2017-05-19 06:56:37 +08:00
|
|
|
#[test]
|
|
|
|
fn from_json_author() {
|
|
|
|
let json = r#"{
|
|
|
|
"author": "John Doe"
|
|
|
|
}"#;
|
|
|
|
|
2017-06-27 15:08:58 +08:00
|
|
|
let parsed = JsonConfig::from_json(json).expect("This should parse");
|
2017-05-19 06:56:37 +08:00
|
|
|
let config = BookConfig::from_jsonconfig("root", parsed);
|
|
|
|
|
|
|
|
assert_eq!(config.get_authors(), &[String::from("John Doe")]);
|
|
|
|
}
|
|
|
|
|
2017-06-01 13:28:08 +08:00
|
|
|
// Tests that the `dest` key is correctly parsed in the JSON config
|
2017-05-19 06:56:37 +08:00
|
|
|
#[test]
|
|
|
|
fn from_json_destination() {
|
|
|
|
let json = r#"{
|
|
|
|
"dest": "htmlbook"
|
|
|
|
}"#;
|
|
|
|
|
2017-06-27 15:08:58 +08:00
|
|
|
let parsed = JsonConfig::from_json(json).expect("This should parse");
|
2017-05-19 06:56:37 +08:00
|
|
|
let config = BookConfig::from_jsonconfig("root", parsed);
|
|
|
|
|
|
|
|
let htmlconfig = config.get_html_config().expect("There should be an HtmlConfig");
|
|
|
|
|
|
|
|
assert_eq!(htmlconfig.get_destination(), PathBuf::from("root/htmlbook"));
|
|
|
|
}
|
|
|
|
|
2017-06-01 13:28:08 +08:00
|
|
|
// Tests that the `theme_path` key is correctly parsed in the JSON config
|
2017-05-19 06:56:37 +08:00
|
|
|
#[test]
|
|
|
|
fn from_json_output_html_theme() {
|
|
|
|
let json = r#"{
|
|
|
|
"theme_path": "theme"
|
|
|
|
}"#;
|
|
|
|
|
2017-06-27 15:08:58 +08:00
|
|
|
let parsed = JsonConfig::from_json(json).expect("This should parse");
|
2017-05-19 06:56:37 +08:00
|
|
|
let config = BookConfig::from_jsonconfig("root", parsed);
|
|
|
|
|
|
|
|
let htmlconfig = config.get_html_config().expect("There should be an HtmlConfig");
|
|
|
|
|
2017-06-23 18:57:58 +08:00
|
|
|
assert_eq!(htmlconfig.get_theme(), &PathBuf::from("root/theme"));
|
2017-06-01 13:28:08 +08:00
|
|
|
}
|