Fix tests

This commit is contained in:
Andrey Voronkov 2024-02-29 08:28:30 +03:00
parent 6f832ed434
commit 7fd73f6ff7
2 changed files with 17 additions and 14 deletions

View File

@ -662,9 +662,10 @@ mod tests {
let got = determine_preprocessors(&cfg); let got = determine_preprocessors(&cfg);
assert!(got.is_ok()); assert!(got.is_ok());
assert_eq!(got.as_ref().unwrap().len(), 2); assert_eq!(got.as_ref().unwrap().len(), 3);
assert_eq!(got.as_ref().unwrap()[0].name(), "index"); assert_eq!(got.as_ref().unwrap()[0].name(), "drinks");
assert_eq!(got.as_ref().unwrap()[1].name(), "links"); assert_eq!(got.as_ref().unwrap()[1].name(), "index");
assert_eq!(got.as_ref().unwrap()[2].name(), "links");
} }
#[test] #[test]

View File

@ -56,17 +56,19 @@ impl Preprocessor for DrinkPreprocessor {
fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result<Book> { fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result<Book> {
let path = ctx.root.join("drinks.txt"); let path = ctx.root.join("drinks.txt");
let drinks: Dict = { if !path.exists() {
return Ok(book);
}
let reader = BufReader::new(File::open(path).expect("Cannot open drinks dictionary")); let reader = BufReader::new(File::open(path).expect("Cannot open drinks dictionary"));
reader let drinks: Dict = reader
.lines() .lines()
.filter_map(|l| { .filter_map(|l| {
l.expect("Cannot read line in drinks dictionary") l.expect("Cannot read line in drinks dictionary")
.split_once(SPLITTER) .split_once(SPLITTER)
.map(|(name, value)| (name.trim().to_owned(), value.trim().to_owned())) .map(|(name, value)| (name.trim().to_owned(), value.trim().to_owned()))
}) })
.collect::<HashMap<_, _>>() .collect::<HashMap<_, _>>();
};
book.for_each_mut(|section: &mut BookItem| { book.for_each_mut(|section: &mut BookItem| {
if let BookItem::Chapter(ref mut ch) = *section { if let BookItem::Chapter(ref mut ch) = *section {