diff options
Diffstat (limited to 'vendor/mdbook/examples')
-rw-r--r-- | vendor/mdbook/examples/nop-preprocessor.rs | 66 |
1 files changed, 61 insertions, 5 deletions
diff --git a/vendor/mdbook/examples/nop-preprocessor.rs b/vendor/mdbook/examples/nop-preprocessor.rs index ace400936..398d7fc78 100644 --- a/vendor/mdbook/examples/nop-preprocessor.rs +++ b/vendor/mdbook/examples/nop-preprocessor.rs @@ -1,5 +1,5 @@ use crate::nop_lib::Nop; -use clap::{App, Arg, ArgMatches}; +use clap::{Arg, ArgMatches, Command}; use mdbook::book::Book; use mdbook::errors::Error; use mdbook::preprocess::{CmdPreprocessor, Preprocessor, PreprocessorContext}; @@ -7,11 +7,11 @@ use semver::{Version, VersionReq}; use std::io; use std::process; -pub fn make_app() -> App<'static> { - App::new("nop-preprocessor") +pub fn make_app() -> Command { + Command::new("nop-preprocessor") .about("A mdbook preprocessor which does precisely nothing") .subcommand( - App::new("supports") + Command::new("supports") .arg(Arg::new("renderer").required(true)) .about("Check whether a renderer is supported by this preprocessor"), ) @@ -54,7 +54,9 @@ fn handle_preprocessing(pre: &dyn Preprocessor) -> Result<(), Error> { } fn handle_supports(pre: &dyn Preprocessor, sub_args: &ArgMatches) -> ! { - let renderer = sub_args.value_of("renderer").expect("Required argument"); + let renderer = sub_args + .get_one::<String>("renderer") + .expect("Required argument"); let supported = pre.supports_renderer(renderer); // Signal whether the renderer is supported by exiting with 1 or 0. @@ -101,4 +103,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); + } + } } |