]> git.proxmox.com Git - rustc.git/blame - src/vendor/mdbook/tests/jsonconfig.rs
New upstream version 1.24.1+dfsg1
[rustc.git] / src / vendor / mdbook / tests / jsonconfig.rs
CommitLineData
ea8adc8c
XL
1extern crate mdbook;
2use mdbook::config::BookConfig;
3use mdbook::config::jsonconfig::JsonConfig;
4
5use std::path::PathBuf;
6
7// Tests that the `src` key is correctly parsed in the JSON config
8#[test]
9fn 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]
22fn 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]
35fn 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]
48fn 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]
61fn 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]
76fn 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}