Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat(core): increase scope of ItsContraction + add tests (#1706)
Elijah Potter5ce7ee6f62c3
diff --git a/harper-core/src/linting/its_contraction.rs b/harper-core/src/linting/its_contraction.rsindex af62138e5..1eb1762e8 100644--- a/harper-core/src/linting/its_contraction.rs+++ b/harper-core/src/linting/its_contraction.rs@@ -24,10 +24,10 @@ pub struct ItsContraction {impl Default for ItsContraction {fn default() -> Self {- let positive = SequenceExpr::default()- .t_aco("its")- .then_whitespace()- .then(UPOSSet::new(&[UPOS::VERB, UPOS::AUX, UPOS::DET]).or(WordSet::new(&["because"])));+ let positive = SequenceExpr::default().t_aco("its").then_whitespace().then(+ UPOSSet::new(&[UPOS::VERB, UPOS::AUX, UPOS::DET, UPOS::PRON])+ .or(WordSet::new(&["because"])),+ );let exceptions = SequenceExpr::default().then_anything()@@ -39,9 +39,9 @@ impl Default for ItsContraction {let expr = All::new(vec![Box::new(positive), Box::new(inverted)]).or_longest(SequenceExpr::aco("its").t_ws()- .then_adjective()+ .then(UPOSSet::new(&[UPOS::ADJ])).t_ws()- .t_aco("for"),+ .then(UPOSSet::new(&[UPOS::SCONJ, UPOS::PART])),);Self {@@ -100,8 +100,10 @@ impl ItsContraction {#[cfg(test)]mod tests {+ use std::default;+use super::ItsContraction;- use crate::linting::tests::{assert_lint_count, assert_suggestion_result};+ use crate::linting::tests::{assert_lint_count, assert_no_lints, assert_suggestion_result};#[test]fn fix_had() {@@ -203,11 +205,84 @@ mod tests {}#[test]- fn because() {+ fn corrects_because() {assert_suggestion_result("Its because they don't want to.",ItsContraction::default(),"It's because they don't want to.",);}++ #[test]+ fn corrects_its_hard() {+ assert_suggestion_result(+ "Its hard to believe that.",+ ItsContraction::default(),+ "It's hard to believe that.",+ );+ }++ #[test]+ fn corrects_its_easy() {+ assert_suggestion_result(+ "Its easy if you try.",+ ItsContraction::default(),+ "It's easy if you try.",+ );+ }++ #[test]+ fn corrects_its_a_picnic() {+ assert_suggestion_result(+ "Its a beautiful day for a picnic",+ ItsContraction::default(),+ "It's a beautiful day for a picnic",+ );+ }++ #[test]+ fn corrects_its_my() {+ assert_suggestion_result(+ "Its my favorite song.",+ ItsContraction::default(),+ "It's my favorite song.",+ );+ }++ #[test]+ fn allows_its_new() {+ assert_no_lints(+ "The company announced its new product line. ",+ ItsContraction::default(),+ );+ }++ #[test]+ fn allows_its_own_charm() {+ assert_no_lints("The house has its own charm. ", ItsContraction::default());+ }++ #[test]+ fn allows_its_victory() {+ assert_no_lints(+ "The team celebrated its victory. ",+ ItsContraction::default(),+ );+ }++ #[test]+ fn allows_its_history() {+ assert_no_lints(+ "The country is proud of its history. ",+ ItsContraction::default(),+ );+ }++ #[test]+ fn allows_its_secrets() {+ assert_no_lints(+ "The book contains its own secrets. ",+ ItsContraction::default(),+ );+ }}diff --git a/harper-core/tests/text/linters/The Great Gatsby.snap.yml b/harper-core/tests/text/linters/The Great Gatsby.snap.ymlindex f44849cc6..f872e11c5 100644--- a/harper-core/tests/text/linters/The Great Gatsby.snap.yml+++ b/harper-core/tests/text/linters/The Great Gatsby.snap.yml@@ -4666,6 +4666,17 @@ Suggest:+Lint: WordChoice (54 priority)+Message: |+ 3495 | It was when curiosity about Gatsby was at its highest that the lights in his+ | ^~~ Use `it's` (short for `it has` or `it is`) here, not the possessive `its`.+ 3496 | house failed to go on one Saturday night—and, as obscurely as it had begun, his+Suggest:+ - Replace with: “it's”+ - Replace with: “it has”+++Lint: Spelling (63 priority)Message: |3496 | house failed to go on one Saturday night—and, as obscurely as it had begun, his