Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat(fst-dict): create FstDictionary-specific tests
Grant Lemons36e1e5f392fc
diff --git a/harper-core/build.rs b/harper-core/build.rsindex d3d6aad35..89a2ac16d 100644--- a/harper-core/build.rs+++ b/harper-core/build.rs@@ -27,12 +27,13 @@ fn main() {// language has that many wordswords.iter().enumerate().for_each(|(i, s)| {build- .insert(s.as_slice().iter().collect::<String>(), i as u64)+ .insert(s.iter().collect::<String>(), i as u64).unwrap()});build.finish().expect("Unable to build map of dictionary!");println!("cargo::rerun-if-changed=build.rs");- println!("cargo::rerun-if-changed=dictionary.dict");+ println!("cargo::rerun-if-changed=dictionary.fst");+ println!("cargo::rerun-if-changed=../harper-dictionary-parsing/dictionary.dict");}diff --git a/harper-core/src/spell/fst_dictionary.rs b/harper-core/src/spell/fst_dictionary.rsindex a5ea79f58..11168a692 100644--- a/harper-core/src/spell/fst_dictionary.rs+++ b/harper-core/src/spell/fst_dictionary.rs@@ -121,6 +121,8 @@ impl Dictionary for FstDictionary {#[cfg(test)]mod tests {+ use fst::IntoStreamer;+use crate::{spell::seq_to_normalized, Dictionary};use super::FstDictionary;@@ -129,15 +131,47 @@ mod tests {fn fst_contains() {let dict = FstDictionary::curated();- for word in dict.words_iter().step_by(5).take(20) {+ for word in dict.words_iter() {let misspelled_word = seq_to_normalized(word);let misspelled_lower: String = misspelled_word.iter().flat_map(|v| v.to_lowercase()).collect();+ println!("{}", misspelled_lower);+ assert!(!misspelled_lower.is_empty());assert!(dict.contains_word(word));assert!(dict.word_map.contains_key(misspelled_lower));}}++ #[test]+ fn fst_words_match() {+ let dict = FstDictionary::curated();++ for (word, i) in dict.word_map.into_stream().into_str_vec().unwrap() {+ let full_dict_word = dict+ .full_dict+ .get_word(i as usize)+ .iter()+ .collect::<String>();+ println!("\"{}\" == \"{}\"?", word, full_dict_word);+ assert_eq!(word, full_dict_word);+ }+ }++ #[test]+ fn fst_contains_hello() {+ let dict = FstDictionary::curated();++ let word: Vec<_> = "hello".chars().collect();+ let misspelled_word = seq_to_normalized(&word);+ let misspelled_lower: String = misspelled_word+ .iter()+ .flat_map(|v| v.to_lowercase())+ .collect();++ assert!(dict.contains_word(&word));+ assert!(dict.word_map.contains_key(misspelled_lower));+ }}