From 3778c145955169735436854e4cef522b332f62f6 Mon Sep 17 00:00:00 2001 From: Elijah Potter Date: Tue, 6 Aug 2024 12:39:50 -0600 Subject: [PATCH] feat: now condenses words with hyphens --- harper-core/src/document.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/harper-core/src/document.rs b/harper-core/src/document.rs index 770a2a9..e15a0b0 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.";