From a9d9fc03a240cd54a19189423df6120a306109b8 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 8 Jun 2023 09:23:10 -0500 Subject: [PATCH] test(dict): Report more cases to user --- crates/typos-dict/tests/verify.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/typos-dict/tests/verify.rs b/crates/typos-dict/tests/verify.rs index 2dcd2e9..2b6b2e1 100644 --- a/crates/typos-dict/tests/verify.rs +++ b/crates/typos-dict/tests/verify.rs @@ -91,11 +91,20 @@ fn generate(file: &mut W, dict: &[u8]) { current.extend(good); } - let corrections: std::collections::HashSet<_> = - dict.values().flatten().map(ToOwned::to_owned).collect(); + let corrections: HashMap<_, _> = dict + .iter() + .flat_map(|(bad, good)| good.iter().map(|good| (good.to_owned(), bad.to_owned()))) + .collect(); let rows: Vec<_> = dict .into_iter() - .filter(|(typo, _)| !corrections.contains(typo.as_str())) + .filter(|(typo, _)| { + if let Some(correction) = corrections.get(typo.as_str()) { + eprintln!("{typo} <-> {correction} cycle detected"); + false + } else { + true + } + }) .collect(); let mut wtr = csv::WriterBuilder::new().flexible(true).from_writer(file);