File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed
Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -65,3 +65,7 @@ search = ["elasticlunr-rs", "ammonia"]
6565[[bin ]]
6666doc = false
6767name = " mdbook"
68+
69+ [[example ]]
70+ name = " nop-preprocessor"
71+ test = true
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments