From ac295bbfcc9cd93007206dd23a29efd7bd5dc2ac Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Wed, 22 Feb 2023 16:30:36 +0900 Subject: [PATCH] Fixing tests and format `cargo test` and `cargo fmt --check` pass. --- src/book/mod.rs | 28 +++++++++++--------- src/config.rs | 1 + src/renderer/html_handlebars/hbs_renderer.rs | 5 +--- tests/init.rs | 4 +-- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/book/mod.rs b/src/book/mod.rs index 61b073ba..f7df3c93 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -202,7 +202,11 @@ impl MDBook { } /// Run the entire build process for a particular [`Renderer`]. - pub fn execute_build_process(&self, renderer: &dyn Renderer, translation: Option<&str>) -> Result<()> { + pub fn execute_build_process( + &self, + renderer: &dyn Renderer, + translation: Option<&str>, + ) -> Result<()> { let mut preprocessed_book = self.book.clone(); let mut config = self.config.clone(); if let Some(translation) = translation { @@ -228,21 +232,21 @@ impl MDBook { build_dir = build_dir.join(translation); } - let mut render_context = RenderContext::new( - self.root.clone(), - preprocessed_book, - config, - build_dir, - ); + let mut render_context = + RenderContext::new(self.root.clone(), preprocessed_book, config, build_dir); render_context .chapter_titles .extend(preprocess_ctx.chapter_titles.borrow_mut().drain()); - info!("Running the {}{} backend", renderer.name(), if let Some(translation) = translation { - format!("[{}]", translation) - } else { - "".to_string() - }); + info!( + "Running the {}{} backend", + renderer.name(), + if let Some(translation) = translation { + format!("[{}]", translation) + } else { + "".to_string() + } + ); renderer .render(&render_context) .with_context(|| "Rendering failed") diff --git a/src/config.rs b/src/config.rs index c1a4ae02..c2ac6247 100644 --- a/src/config.rs +++ b/src/config.rs @@ -772,6 +772,7 @@ mod tests { multilingual: true, src: PathBuf::from("source"), language: Some(String::from("ja")), + ..Default::default() }; let build_should_be = BuildConfig { build_dir: PathBuf::from("outputs"), diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index a6874ffc..0d7adce9 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -637,10 +637,7 @@ fn make_data( json!(config.book.language.clone().unwrap_or_default()), ); if !config.book.translations.is_empty() { - data.insert( - "translations".to_owned(), - json!(config.book.translations), - ); + data.insert("translations".to_owned(), json!(config.book.translations)); } data.insert( "book_title".to_owned(), diff --git a/tests/init.rs b/tests/init.rs index 2b6ad507..98d7ae38 100644 --- a/tests/init.rs +++ b/tests/init.rs @@ -29,7 +29,7 @@ fn base_mdbook_init_should_create_default_content() { let contents = fs::read_to_string(temp.path().join("book.toml")).unwrap(); assert_eq!( contents, - "[book]\nauthors = []\nlanguage = \"en\"\nmultilingual = false\nsrc = \"src\"\n" + "[book]\nauthors = []\nlanguage = \"en\"\nmultilingual = false\nsrc = \"src\"\ntranslations = []\n" ); } @@ -96,7 +96,7 @@ fn run_mdbook_init_with_custom_book_and_src_locations() { let contents = fs::read_to_string(temp.path().join("book.toml")).unwrap(); assert_eq!( contents, - "[book]\nauthors = []\nlanguage = \"en\"\nmultilingual = false\nsrc = \"in\"\n\n[build]\nbuild-dir = \"out\"\ncreate-missing = true\nextra-watch-dirs = []\nuse-default-preprocessors = true\n" + "[book]\nauthors = []\nlanguage = \"en\"\nmultilingual = false\nsrc = \"in\"\ntranslations = []\n\n[build]\nbuild-dir = \"out\"\ncreate-missing = true\nextra-watch-dirs = []\nuse-default-preprocessors = true\n" ); }