summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoritada Kobayashi <noritada.kobayashi@gmail.com>2022-09-25 06:32:41 +0900
committerGitHub <noreply@github.com>2022-09-24 14:32:41 -0700
commit7aaa84853d8991d895f53d27630a2a1c10bd9531 (patch)
tree13a30c393546e966c045a227bfb33a7c5dcd041f
parent75857fbf739905bd6eac53751ac945bab33b0c99 (diff)
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.
-rw-r--r--Cargo.toml4
-rw-r--r--examples/nop-preprocessor.rs54
2 files changed, 58 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 07b2ed78..5b564ec9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -65,3 +65,7 @@ search = ["elasticlunr-rs", "ammonia"]
[[bin]]
doc = false
name = "mdbook"
+
+[[example]]
+name = "nop-preprocessor"
+test = true
diff --git a/examples/nop-preprocessor.rs b/examples/nop-preprocessor.rs
index ace40093..a5e47daa 100644
--- a/examples/nop-preprocessor.rs
+++ b/examples/nop-preprocessor.rs
@@ -101,4 +101,58 @@ mod nop_lib {
renderer != "not-supported"
}
}
+
+ #[cfg(test)]
+ mod test {
+ use super::*;
+
+ #[test]
+ fn nop_preprocessor_run() {
+ let input_json = r##"[
+ {
+ "root": "/path/to/book",
+ "config": {
+ "book": {
+ "authors": ["AUTHOR"],
+ "language": "en",
+ "multilingual": false,
+ "src": "src",
+ "title": "TITLE"
+ },
+ "preprocessor": {
+ "nop": {}
+ }
+ },
+ "renderer": "html",
+ "mdbook_version": "0.4.21"
+ },
+ {
+ "sections": [
+ {
+ "Chapter": {
+ "name": "Chapter 1",
+ "content": "# Chapter 1\n",
+ "number": [1],
+ "sub_items": [],
+ "path": "chapter_1.md",
+ "source_path": "chapter_1.md",
+ "parent_names": []
+ }
+ }
+ ],
+ "__non_exhaustive": null
+ }
+ ]"##;
+ let input_json = input_json.as_bytes();
+
+ let (ctx, book) = mdbook::preprocess::CmdPreprocessor::parse_input(input_json).unwrap();
+ let expected_book = book.clone();
+ let result = Nop::new().run(&ctx, book);
+ assert!(result.is_ok());
+
+ // The nop-preprocessor should not have made any changes to the book content.
+ let actual_book = result.unwrap();
+ assert_eq!(actual_book, expected_book);
+ }
+ }
}