Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix(core): improper pattern

Elijah Pottereb59b19c335b
diff --git a/harper-core/src/linting/pronoun_contraction/should_contract.rs b/harper-core/src/linting/pronoun_contraction/should_contract.rs
index af480636d..fcb519ebb 100644
--- a/harper-core/src/linting/pronoun_contraction/should_contract.rs
+++ b/harper-core/src/linting/pronoun_contraction/should_contract.rs
@@ -17,9 +17,9 @@ impl Default for ShouldContract {
SequencePattern::default()
.then(WordSet::new(&["your", "were"]))
.then_whitespace()
- .t_aco("the")
+ .then_article()
.then_whitespace()
- .then_noun(),
+ .then_adjective(),
),
}
}
@@ -60,3 +60,47 @@ impl PatternLinter for ShouldContract {
"Neglecting the apostrophe when contracting pronouns with \"are\" (like \"your\" and \"you are\") is a fatal, but extremely common mistake to make."
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::ShouldContract;
+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};
+
+ #[test]
+ fn contracts_your_correctly() {
+ assert_suggestion_result(
+ "your the best",
+ ShouldContract::default(),
+ "you're the best",
+ );
+ }
+
+ #[test]
+ fn contracts_were_complex_correctly() {
+ assert_suggestion_result(
+ "were a good team",
+ ShouldContract::default(),
+ "we're a good team",
+ );
+ }
+
+ #[test]
+ fn case_insensitive_handling() {
+ assert_suggestion_result(
+ "Your the best",
+ ShouldContract::default(),
+ "You're the best",
+ );
+ }
+
+ #[test]
+ fn no_match_without_the() {
+ assert_lint_count("your best", ShouldContract::default(), 0);
+ assert_lint_count("were best", ShouldContract::default(), 0);
+ }
+
+ #[test]
+ fn no_match_with_punctuation() {
+ assert_lint_count("your, the best", ShouldContract::default(), 0);
+ }
+}