Skip to content

Commit 7aaa848

Browse files
authored
Add test code to show preprocessor developers what the interface data looks like (#1897)
This test code will show preprocessor developers what the input data looks like and how to test the preprocessing results.
1 parent 75857fb commit 7aaa848

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ search = ["elasticlunr-rs", "ammonia"]
6565
[[bin]]
6666
doc = false
6767
name = "mdbook"
68+
69+
[[example]]
70+
name = "nop-preprocessor"
71+
test = true

examples/nop-preprocessor.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,58 @@ mod nop_lib {
101101
renderer != "not-supported"
102102
}
103103
}
104+
105+
#[cfg(test)]
106+
mod test {
107+
use super::*;
108+
109+
#[test]
110+
fn nop_preprocessor_run() {
111+
let input_json = r##"[
112+
{
113+
"root": "/path/to/book",
114+
"config": {
115+
"book": {
116+
"authors": ["AUTHOR"],
117+
"language": "en",
118+
"multilingual": false,
119+
"src": "src",
120+
"title": "TITLE"
121+
},
122+
"preprocessor": {
123+
"nop": {}
124+
}
125+
},
126+
"renderer": "html",
127+
"mdbook_version": "0.4.21"
128+
},
129+
{
130+
"sections": [
131+
{
132+
"Chapter": {
133+
"name": "Chapter 1",
134+
"content": "# Chapter 1\n",
135+
"number": [1],
136+
"sub_items": [],
137+
"path": "chapter_1.md",
138+
"source_path": "chapter_1.md",
139+
"parent_names": []
140+
}
141+
}
142+
],
143+
"__non_exhaustive": null
144+
}
145+
]"##;
146+
let input_json = input_json.as_bytes();
147+
148+
let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap();
149+
let expected_book = book.clone();
150+
let result = Nop::new().run(&ctx, book);
151+
assert!(result.is_ok());
152+
153+
// The nop-preprocessor should not have made any changes to the book content.
154+
let actual_book = result.unwrap();
155+
assert_eq!(actual_book, expected_book);
156+
}
157+
}
104158
}

0 commit comments

Comments
 (0)