]>
Commit | Line | Data |
---|---|---|
ea8adc8c XL |
1 | extern crate mdbook; |
2 | use mdbook::config::BookConfig; | |
3 | use mdbook::config::jsonconfig::JsonConfig; | |
4 | ||
5 | use std::path::PathBuf; | |
6 | ||
7 | // Tests that the `src` key is correctly parsed in the JSON config | |
8 | #[test] | |
9 | fn from_json_source() { | |
10 | let json = r#"{ | |
11 | "src": "source" | |
12 | }"#; | |
13 | ||
14 | let parsed = JsonConfig::from_json(json).expect("This should parse"); | |
15 | let config = BookConfig::from_jsonconfig("root", parsed); | |
16 | ||
17 | assert_eq!(config.get_source(), PathBuf::from("root/source")); | |
18 | } | |
19 | ||
20 | // Tests that the `title` key is correctly parsed in the JSON config | |
21 | #[test] | |
22 | fn from_json_title() { | |
23 | let json = r#"{ | |
24 | "title": "Some title" | |
25 | }"#; | |
26 | ||
27 | let parsed = JsonConfig::from_json(json).expect("This should parse"); | |
28 | let config = BookConfig::from_jsonconfig("root", parsed); | |
29 | ||
30 | assert_eq!(config.get_title(), "Some title"); | |
31 | } | |
32 | ||
33 | // Tests that the `description` key is correctly parsed in the JSON config | |
34 | #[test] | |
35 | fn from_json_description() { | |
36 | let json = r#"{ | |
37 | "description": "This is a description" | |
38 | }"#; | |
39 | ||
40 | let parsed = JsonConfig::from_json(json).expect("This should parse"); | |
41 | let config = BookConfig::from_jsonconfig("root", parsed); | |
42 | ||
43 | assert_eq!(config.get_description(), "This is a description"); | |
44 | } | |
45 | ||
46 | // Tests that the `author` key is correctly parsed in the JSON config | |
47 | #[test] | |
48 | fn from_json_author() { | |
49 | let json = r#"{ | |
50 | "author": "John Doe" | |
51 | }"#; | |
52 | ||
53 | let parsed = JsonConfig::from_json(json).expect("This should parse"); | |
54 | let config = BookConfig::from_jsonconfig("root", parsed); | |
55 | ||
56 | assert_eq!(config.get_authors(), &[String::from("John Doe")]); | |
57 | } | |
58 | ||
59 | // Tests that the `dest` key is correctly parsed in the JSON config | |
60 | #[test] | |
61 | fn from_json_destination() { | |
62 | let json = r#"{ | |
63 | "dest": "htmlbook" | |
64 | }"#; | |
65 | ||
66 | let parsed = JsonConfig::from_json(json).expect("This should parse"); | |
67 | let config = BookConfig::from_jsonconfig("root", parsed); | |
68 | ||
69 | let htmlconfig = config.get_html_config(); | |
70 | ||
71 | assert_eq!(htmlconfig.get_destination(), PathBuf::from("root/htmlbook")); | |
72 | } | |
73 | ||
74 | // Tests that the `theme_path` key is correctly parsed in the JSON config | |
75 | #[test] | |
76 | fn from_json_output_html_theme() { | |
77 | let json = r#"{ | |
78 | "theme_path": "theme" | |
79 | }"#; | |
80 | ||
81 | let parsed = JsonConfig::from_json(json).expect("This should parse"); | |
82 | let config = BookConfig::from_jsonconfig("root", parsed); | |
83 | ||
84 | let htmlconfig = config.get_html_config(); | |
85 | ||
86 | assert_eq!(htmlconfig.get_theme(), &PathBuf::from("root/theme")); | |
87 | } |