Fixing tests and format

`cargo test` and `cargo fmt --check` pass.
This commit is contained in:
Jooyung Han 2023-02-22 16:30:36 +09:00
parent e166a1f2a4
commit ac295bbfcc
4 changed files with 20 additions and 18 deletions

View File

@ -202,7 +202,11 @@ impl MDBook {
} }
/// Run the entire build process for a particular [`Renderer`]. /// 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 preprocessed_book = self.book.clone();
let mut config = self.config.clone(); let mut config = self.config.clone();
if let Some(translation) = translation { if let Some(translation) = translation {
@ -228,21 +232,21 @@ impl MDBook {
build_dir = build_dir.join(translation); build_dir = build_dir.join(translation);
} }
let mut render_context = RenderContext::new( let mut render_context =
self.root.clone(), RenderContext::new(self.root.clone(), preprocessed_book, config, build_dir);
preprocessed_book,
config,
build_dir,
);
render_context render_context
.chapter_titles .chapter_titles
.extend(preprocess_ctx.chapter_titles.borrow_mut().drain()); .extend(preprocess_ctx.chapter_titles.borrow_mut().drain());
info!("Running the {}{} backend", renderer.name(), if let Some(translation) = translation { info!(
format!("[{}]", translation) "Running the {}{} backend",
} else { renderer.name(),
"".to_string() if let Some(translation) = translation {
}); format!("[{}]", translation)
} else {
"".to_string()
}
);
renderer renderer
.render(&render_context) .render(&render_context)
.with_context(|| "Rendering failed") .with_context(|| "Rendering failed")

View File

@ -772,6 +772,7 @@ mod tests {
multilingual: true, multilingual: true,
src: PathBuf::from("source"), src: PathBuf::from("source"),
language: Some(String::from("ja")), language: Some(String::from("ja")),
..Default::default()
}; };
let build_should_be = BuildConfig { let build_should_be = BuildConfig {
build_dir: PathBuf::from("outputs"), build_dir: PathBuf::from("outputs"),

View File

@ -637,10 +637,7 @@ fn make_data(
json!(config.book.language.clone().unwrap_or_default()), json!(config.book.language.clone().unwrap_or_default()),
); );
if !config.book.translations.is_empty() { if !config.book.translations.is_empty() {
data.insert( data.insert("translations".to_owned(), json!(config.book.translations));
"translations".to_owned(),
json!(config.book.translations),
);
} }
data.insert( data.insert(
"book_title".to_owned(), "book_title".to_owned(),

View File

@ -29,7 +29,7 @@ fn base_mdbook_init_should_create_default_content() {
let contents = fs::read_to_string(temp.path().join("book.toml")).unwrap(); let contents = fs::read_to_string(temp.path().join("book.toml")).unwrap();
assert_eq!( assert_eq!(
contents, 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(); let contents = fs::read_to_string(temp.path().join("book.toml")).unwrap();
assert_eq!( assert_eq!(
contents, 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"
); );
} }