Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: now condenses words with hyphens
Elijah Potter3778c1459551
diff --git a/harper-core/src/document.rs b/harper-core/src/document.rsindex 770a2a9c3..e15a0b063 100644--- a/harper-core/src/document.rs+++ b/harper-core/src/document.rs@@ -467,8 +467,8 @@ impl Document {self.tokens.remove_indices(to_remove);}- /// Searches for contractions and condenses them down into single- /// tokens.+ /// Searches for contractions and hyphenated words and condenses them down+ /// into single tokens.fn condense_contractions(&mut self) {if self.tokens.len() < 3 {return;@@ -488,6 +488,10 @@ impl Document {TokenKind::Word(..),TokenKind::Punctuation(Punctuation::Apostrophe),TokenKind::Word(..)+ ) | (+ TokenKind::Word(..),+ TokenKind::Punctuation(Punctuation::Hyphen),+ TokenKind::Word(..))) {// Ensure there is no overlapping between replacements@@ -648,6 +652,15 @@ mod tests {assert_condensed_contractions("There's no way", 5);}+ #[test]+ fn condenses_pre_existing() {+ assert_condensed_contractions("pre-existing", 1);+ assert_condensed_contractions(+ "There was a pre-existing problem with words with hyphens.",+ 18+ );+ }+#[test]fn selects_token_at_char_index() {let text = "There were three little pigs. They built three little homes.";