Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(core): ignore whitespace when matching case (#1165)
Elijah Potter34698df45afb
diff --git a/harper-core/src/linting/hop_hope/mod.rs b/harper-core/src/linting/hop_hope/mod.rsindex eb63d18e6..e25118ae5 100644--- a/harper-core/src/linting/hop_hope/mod.rs+++ b/harper-core/src/linting/hop_hope/mod.rs@@ -35,7 +35,7 @@ mod tests {assert_suggestion_result("I HoP we can find a solution.",HopHope::default(),- "I HoPe we can find a solution.",+ "I HoPE we can find a solution.",);}@@ -80,7 +80,7 @@ mod tests {assert_suggestion_result("She HoPeD on a train to get home.",HopHope::default(),- "She HoPpEd on a train to get home.",+ "She HoPpED on a train to get home.",);}}diff --git a/harper-core/src/linting/suggestion.rs b/harper-core/src/linting/suggestion.rsindex 0941ebb67..310962759 100644--- a/harper-core/src/linting/suggestion.rs+++ b/harper-core/src/linting/suggestion.rs@@ -28,7 +28,18 @@ impl Suggestion {/// For example, if we want to replace "You're" with "You are", we can provide "you are" and/// "You're".pub fn replace_with_match_case(mut value: Vec<char>, template: &[char]) -> Self {- for (v, t) in value.iter_mut().zip(template.iter()) {+ // If the value is longer than the template, use this.+ let template_term = [template.last().copied().unwrap_or('l')]+ .into_iter()+ .cycle();++ for (v, t) in value.iter_mut().filter(|v| v.is_alphabetic()).zip(+ template+ .iter()+ .filter(|v| v.is_alphabetic())+ .copied()+ .chain(template_term),+ ) {if v.is_ascii_uppercase() != t.is_ascii_uppercase() {if t.is_uppercase() {*v = v.to_ascii_uppercase();@@ -115,4 +126,17 @@ mod tests {Suggestion::ReplaceWith(correct))}++ #[test]+ fn issue_1065() {+ let template: Vec<_> = "Stack Overflow".chars().collect();+ let value: Vec<_> = "stackoverflow".chars().collect();++ let correct = "StackOverflow".chars().collect();++ assert_eq!(+ Suggestion::replace_with_match_case(value, &template),+ Suggestion::ReplaceWith(correct)+ )+ }}