Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
Merge branch 'master' into dialect-prototyping
Elijah Potter24b2d026239d
diff --cc harper-core/src/spell/mod.rsindex 3964bbf41,6ea5d784d..e97354ae7--- a/harper-core/src/spell/mod.rs+++ b/harper-core/src/spell/mod.rs@@@ -109,8 -125,8 +109,8 @@@ mod tests#[test]fn normalizes_weve() {-- let word = vec!['w', 'e', '’', 'v', 'e'];- let norm = seq_to_normalized(&word);++ let word = ['w', 'e', '’', 'v', 'e'];+ let norm = word.normalized();assert_eq!(norm.clone(), vec!['w', 'e', '\'', 'v', 'e'])}diff --cc harper-core/src/spell/rune/mod.rsindex 50a0f1eea,19bcecdc7..d8e332511--- a/harper-core/src/spell/rune/mod.rs+++ b/harper-core/src/spell/rune/mod.rs@@@ -28,21 -28,26 +28,27 @@@ pub fn parse_default_attribute_list() -#[cfg(test)]mod tests {- use hashbrown::{HashMap, HashSet};+ use hashbrown::HashSet;+ use once_cell::sync::Lazy;use serde_json::json;+ use super::super::word_map::WordMap;+ use super::HumanReadableAttributeList;use super::word_list::parse_word_list;use super::{parse_default_attribute_list, parse_default_word_list};- use crate::spell::hunspell::attribute_list::HumanReadableAttributeList;- use crate::{CharString, WordMetadata};+ use crate::CharStringExt;- pub const TEST_WORD_LIST: &str = "3\nhello\ntry/B\nwork/AB";+ pub const TEST_WORD_LIST: &str = "4\nhello\ntry/B\nwork/AB\nblank/";- #[test]- fn correctly_expands_test_files() {- let words = parse_word_list(TEST_WORD_LIST).unwrap();- let attributes: HumanReadableAttributeList = serde_json::from_value(json!({+ pub const TEST_WORD_LIST_WITH_BLANK_LINES: &str = "4\n\nhello\n\ntry/B\nwork/AB\n\n\nblank/";++ pub const TEST_WORD_LIST_WITH_FULL_LINE_COMMENTS: &str =+ "4\n#\nhello\n#with\ntry/B\nwork/AB\n# some\n# comments aded\nblank/";++ pub const TEST_WORD_LIST_WITH_COMMENTS: &str = "4\nhello # a word without attributes\ntry/B \t # a word with empty attributes\nwork/AB\t #a word with one attribute\nblank/ #a word with two attributes";+- pub const TEST_AFFIX_JSON: Lazy<serde_json::Value> = Lazy::new(|| {++ pub static TEST_AFFIX_JSON: Lazy<serde_json::Value> = Lazy::new(|| {+ json!({"affixes": {"A": {"suffix": false,@@@ -82,11 -87,63 +88,63 @@@"gifts_metadata": {}}}- }))- .unwrap();+ })+ });++ fn assert_expansion_results(test_word_list: &str, expected: Vec<&str>) {+ let words = parse_word_list(test_word_list).unwrap();+ let attributes: HumanReadableAttributeList =+ serde_json::from_value(TEST_AFFIX_JSON.clone()).unwrap();+ let attributes = attributes.into_normal().unwrap();+- let mut expanded = HashMap::new();++ let mut expanded = WordMap::default();+ attributes.expand_marked_words(words, &mut expanded);+ let expanded: HashSet<String> = expanded+ .into_iter()- .map(|v| v.0.into_iter().collect())++ .map(|v| v.canonical_spelling.into_iter().collect())+ .collect();++ assert_eq!(expanded, expected.into_iter().map(|v| v.into()).collect());+ }++ #[test]+ fn correctly_expands_test_files() {+ assert_expansion_results(+ TEST_WORD_LIST,+ vec![+ "reworked", "rework", "tried", "try", "hello", "worked", "work", "blank",+ ],+ );+ }++ #[test]+ fn correctly_expands_test_files_with_blank_lines() {+ assert_expansion_results(+ TEST_WORD_LIST_WITH_BLANK_LINES,+ vec![+ "reworked", "rework", "tried", "try", "hello", "worked", "work", "blank",+ ],+ );+ }++ fn correctly_expands_test_files_with_full_line_comments() {+ assert_expansion_results(+ TEST_WORD_LIST_WITH_FULL_LINE_COMMENTS,+ vec![+ "reworked", "rework", "tried", "try", "hello", "worked", "work", "blank",+ ],+ );+ }++ #[test]+ fn correctly_expands_test_files_with_comments() {+ let words = parse_word_list(TEST_WORD_LIST_WITH_COMMENTS).unwrap();++ let attributes: HumanReadableAttributeList =+ serde_json::from_value(TEST_AFFIX_JSON.clone()).unwrap();let attributes = attributes.into_normal().unwrap();- let mut expanded = HashMap::new();+ let mut expanded = WordMap::default();attributes.expand_marked_words(words, &mut expanded);let expanded: HashSet<String> = expanded