From a4b7ed7a42c716ab9f05e351f003d589124fd55d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:58 +0200 Subject: Adding upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- vendor/mdbook/examples/nop-preprocessor.rs | 66 +++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 5 deletions(-) (limited to 'vendor/mdbook/examples') 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::("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); + } + } } -- cgit v1.2.3