From a3a9c9fd8bbd53a4e410a85e42428ba1fc1b26b1 Mon Sep 17 00:00:00 2001 From: hippietrail Date: Wed, 26 Feb 2025 00:50:40 +0800 Subject: [PATCH] test: check that dictionary attributes can be spread over two entries In other words you can put all the flags after `/` in a single entry even if the word covers multiple homographs and senses - or you can put each on its own line with just the flags relevant to it - and the result will be the same. --- harper-core/src/spell/hunspell/mod.rs | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/harper-core/src/spell/hunspell/mod.rs b/harper-core/src/spell/hunspell/mod.rs index 886548db..bf228dfe 100644 --- a/harper-core/src/spell/hunspell/mod.rs +++ b/harper-core/src/spell/hunspell/mod.rs @@ -234,6 +234,35 @@ mod tests { assert!(is.unwrap().is_linking_verb()); } + #[test] + fn are_merged_attrs_same_as_spread_attrs() { + let merged_word = parse_word_list("1\nblork/DGS").unwrap(); + let spread_word = parse_word_list("2\nblork/DG\nblork/S").unwrap(); + + let merged_attrs = parse_default_attribute_list(); + let spread_attrs = parse_default_attribute_list(); + + let mut expanded1 = HashMap::new(); + let mut expanded2 = HashMap::new(); + + merged_attrs.expand_marked_words(merged_word, &mut expanded1); + let expanded_merged: HashSet = expanded1 + .into_iter() + .map(|v| v.0.into_iter().collect()) + .collect(); + + spread_attrs.expand_marked_words(spread_word, &mut expanded2); + let expanded_spread: HashSet = expanded2 + .into_iter() + .map(|v| v.0.into_iter().collect()) + .collect(); + + assert_eq!( + expanded_merged.into_iter().collect::>(), + expanded_spread.into_iter().collect::>() + ); + } + fn split(text: &str) -> CharString { text.chars().collect() }