Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: tests for comment lines, comments, and also blank affixes
hippietraila9c71a206a08
diff --git a/harper-core/src/spell/hunspell/mod.rs b/harper-core/src/spell/hunspell/mod.rsindex 886548dbf..4195a8bb6 100644--- a/harper-core/src/spell/hunspell/mod.rs+++ b/harper-core/src/spell/hunspell/mod.rs@@ -36,7 +36,11 @@ mod tests {use crate::spell::hunspell::attribute_list::HumanReadableAttributeList;use crate::{CharString, WordMetadata};- 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/";++ 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_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";#[test]fn correctly_expands_test_files() {@@ -96,7 +100,139 @@ mod tests {assert_eq!(expanded,vec![- "hello", "tried", "reworked", "rework", "worked", "work", "try"+ "reworked", "rework", "tried", "try", "hello", "worked", "work", "blank"+ ]+ .into_iter()+ .map(|v| v.into())+ .collect()+ )+ }++ #[test]+ fn correctly_expands_test_files_with_blank_lines() {+ let words = parse_word_list(TEST_WORD_LIST_WITH_BLANK_LINES).unwrap();+ let attributes: HumanReadableAttributeList = serde_json::from_value(json!({+ "affixes": {+ "A": {+ "suffix": false,+ "cross_product": true,+ "replacements": [+ {+ "remove": "",+ "add": "re",+ "condition": "."+ }+ ],+ "adds_metadata": {+ "kind": null,+ "tense": null+ },+ "gifts_metadata": {}+ },+ "B": {+ "suffix": true,+ "cross_product": true,+ "replacements": [+ {+ "remove": "",+ "add": "ed",+ "condition": "[^y]"+ },+ {+ "remove": "y",+ "add": "ied",+ "condition": "y"+ }+ ],+ "adds_metadata": {+ "kind": null,+ "tense": null+ },+ "gifts_metadata": {}+ }+ }+ }))+ .unwrap();+ let attributes = attributes.into_normal().unwrap();++ let mut expanded = HashMap::new();++ attributes.expand_marked_words(words, &mut expanded);+ let expanded: HashSet<String> = expanded+ .into_iter()+ .map(|v| v.0.into_iter().collect())+ .collect();++ assert_eq!(+ expanded,+ vec![+ "reworked", "rework", "tried", "try", "hello", "worked", "work", "blank"+ ]+ .into_iter()+ .map(|v| v.into())+ .collect()+ )+ }++ #[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(json!({+ "affixes": {+ "A": {+ "suffix": false,+ "cross_product": true,+ "replacements": [+ {+ "remove": "",+ "add": "re",+ "condition": "."+ }+ ],+ "adds_metadata": {+ "kind": null,+ "tense": null+ },+ "gifts_metadata": {}+ },+ "B": {+ "suffix": true,+ "cross_product": true,+ "replacements": [+ {+ "remove": "",+ "add": "ed",+ "condition": "[^y]"+ },+ {+ "remove": "y",+ "add": "ied",+ "condition": "y"+ }+ ],+ "adds_metadata": {+ "kind": null,+ "tense": null+ },+ "gifts_metadata": {}+ }+ }+ }))+ .unwrap();+ let attributes = attributes.into_normal().unwrap();++ let mut expanded = HashMap::new();++ attributes.expand_marked_words(words, &mut expanded);+ let expanded: HashSet<String> = expanded+ .into_iter()+ .map(|v| v.0.into_iter().collect())+ .collect();++ assert_eq!(+ expanded,+ vec![+ "reworked", "rework", "tried", "try", "hello", "worked", "work", "blank"].into_iter().map(|v| v.into())diff --git a/harper-core/src/spell/hunspell/word_list.rs b/harper-core/src/spell/hunspell/word_list.rsindex 6750cb155..c18f88f37 100644--- a/harper-core/src/spell/hunspell/word_list.rs+++ b/harper-core/src/spell/hunspell/word_list.rs@@ -66,7 +66,7 @@ mod tests {fn can_parse_test_file() {let list = parse_word_list(TEST_WORD_LIST).unwrap();- assert_eq!(list.last().unwrap().attributes.len(), 2);- assert_eq!(list.len(), 3);+ assert_eq!(list.last().unwrap().attributes.len(), 0);+ assert_eq!(list.len(), 4);}}