Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: womans→women, writed→wrote, etc. (#2812)
Andrew Dunbar86b18688291c
diff --git a/harper-core/irregular_nouns.json b/harper-core/irregular_nouns.jsonindex edc61312f..792ff6732 100644--- a/harper-core/irregular_nouns.json+++ b/harper-core/irregular_nouns.json@@ -1,15 +1,6 @@["// comments can appear in the line before an entry","// or in place of an entry",- ["child", "children"],- ["foot", "feet"],- ["goose", "geese"],- ["man", "men"],- ["mouse", "mice"],- ["ox", "oxen"],- ["person", "people"],- ["seraph", "seraphim"],- ["woman", "women"],["addendum", "addenda"],["aircraft", "aircraft"],["aircraftman", "aircraftmen"],@@ -37,6 +28,7 @@["catharsis", "catharses"],["chairman", "chairmen"],["chairwoman", "chairwomen"],+ ["child", "children"],["churchwoman", "churchwomen"],["clansman", "clansmen"],["clanswoman", "clanswomen"],@@ -49,6 +41,7 @@["crisis", "crises"],["cyclops", "cyclopes"],["datum", "data"],+ ["deer", "deer"],["diaeresis", "diaereses"],["diagnosis", "diagnoses"],["dominatrix", "dominatrices"],@@ -59,6 +52,7 @@["esophagus", "esophagi"],["extremum", "extrema"],["fish", "fish"],+ ["foot", "feet"],["footman", "footmen"],["formula", "formulae"],["forum", "fora"],@@ -71,6 +65,7 @@["genius", "genii"],["genus", "genera"],["glissando", "glissandi"],+ ["goose", "geese"],["graffito", "graffiti"],["grandchild", "grandchildren"],["handyman", "handymen"],@@ -91,11 +86,13 @@["louse", "lice"],["madman", "madmen"],["mailman", "mailmen"],+ ["man", "men"],["memorandum", "memoranda"],["metathesis", "metatheses"],["minimum", "minima"],["mitosis", "mitoses"],["motorman", "motormen"],+ ["mouse", "mice"],["muscleman", "musclemen"],["nemesis", "nemeses"],["nightwatchman", "nightwatchmen"],@@ -104,6 +101,7 @@["oasis", "oases"],["ombudsman", "ombudsmen"],["optimum", "optima"],+ ["ox", "oxen"],["palazzo", "palazzi"],["papyrus", "papyri"],["parenthesis", "parentheses"],@@ -111,6 +109,7 @@["patrolman", "patrolmen"],["pericardium", "pericardia"],["periphrasis", "periphrases"],+ ["person", "people"],["pharynx", "pharynges"],["phenomenon", "phenomena"],["plainclothesman", "plainclothesmen"],@@ -125,11 +124,13 @@["saleswoman", "saleswomen"],["sandman", "sandmen"],["schema", "schemata"],+ ["seraph", "seraphim"],["sheep", "sheep"],["shoreman", "shoremen"],["signore", "signori"],["simulacrum", "simulacra"],["solarium", "solaria"],+ ["species", "species"],["spokesman", "spokesmen"],["spokesperson", "spokespeople"],["spokeswoman", "spokeswomen"],@@ -156,6 +157,7 @@["vertex", "vertices"],["vivarium", "vivaria"],["washerwoman", "washerwomen"],+ ["woman", "women"],["woodlouse", "woodlice"],["workingwoman", "workingwomen"],["workman", "workmen"]diff --git a/harper-core/irregular_verbs.json b/harper-core/irregular_verbs.jsonindex 801746803..03430069c 100644--- a/harper-core/irregular_verbs.json+++ b/harper-core/irregular_verbs.json@@ -73,6 +73,7 @@["overwrite", "overwrote", "overwritten"],["partake", "partook", "partaken"],["pay", "paid", "paid"],+ "// prove -- proved -- proven/proved",["put", "put", "put"],["read", "read", "read"],["redo", "redid", "redone"],@@ -87,6 +88,7 @@["sell", "sold", "sold"],["send", "sent", "sent"],["set", "set", "set"],+ ["sew", "sewed", "sewn"],["shake", "shook", "shaken"],["shed", "shed", "shed"],["shine", "shone", "shone"],@@ -119,7 +121,6 @@["stride", "strode", "stridden"],["strike", "struck", "stricken"],["string", "strung", "strung"],- ["sew", "sewed", "sewn"],["swear", "swore", "sworn"],["sweep", "swept", "swept"],["swell", "swelled", "swollen"],diff --git a/harper-core/src/document.rs b/harper-core/src/document.rsindex 33a7a2a52..dd8638ed4 100644--- a/harper-core/src/document.rs+++ b/harper-core/src/document.rs@@ -81,6 +81,16 @@ impl Document {document}+ /// Create a new document from character data using the built-in [`PlainEnglish`]+ /// parser and curated dictionary. This avoids string-to-char conversions.+ pub fn new_plain_english_curated_chars(source: &[char]) -> Self {+ Self::new_from_vec(+ Lrc::new(source.to_vec()),+ &PlainEnglish,+ &FstDictionary::curated(),+ )+ }+/// Parse text to produce a document using the built-in [`PlainEnglish`]/// parser and curated dictionary.pub fn new_plain_english_curated(text: &str) -> Self {@@ -116,6 +126,16 @@ impl Document {)}+ /// Create a new document from character data using the built-in [`Markdown`] parser+ /// and curated dictionary. This avoids string-to-char conversions.+ pub fn new_markdown_default_curated_chars(chars: &[char]) -> Self {+ Self::new_from_vec(+ chars.to_vec().into(),+ &Markdown::default(),+ &FstDictionary::curated(),+ )+ }+/// Parse text to produce a document using the built-in [`Markdown`] parser/// and curated dictionary with the default Markdown configuration.pub fn new_markdown_default_curated(text: &str) -> Self {diff --git a/harper-core/src/irregular_verbs.rs b/harper-core/src/irregular_verbs.rsindex 42f792fc5..1084745c5 100644--- a/harper-core/src/irregular_verbs.rs+++ b/harper-core/src/irregular_verbs.rs@@ -70,6 +70,13 @@ impl IrregularVerbs {.find(|(_, pt, _)| pt.eq_ignore_ascii_case(preterite)).map(|(lemma, _, _)| lemma.as_str())}++ pub fn get_pasts_for_lemma(&self, lemma: &str) -> Option<(&str, &str)> {+ self.verbs+ .iter()+ .find(|(l, _, _)| l.eq_ignore_ascii_case(lemma))+ .map(|(_, pt, pp)| (pt.as_str(), pp.as_str()))+ }}impl Default for IrregularVerbs {diff --git a/harper-core/src/linting/a_part.rs b/harper-core/src/linting/a_part.rsindex e86f4c769..c3a81cd2f 100644--- a/harper-core/src/linting/a_part.rs+++ b/harper-core/src/linting/a_part.rs@@ -88,7 +88,7 @@ impl ExprLinter for APart {#[cfg(test)]mod tests {use super::APart;- use crate::linting::tests::{assert_lint_count, assert_top3_suggestion_result};+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};#[test]fn allow_normal_use_of_a_part() {@@ -126,7 +126,7 @@ mod tests {#[test]fn corrects_a_part_from_to_apart_from_format() {- assert_top3_suggestion_result(+ assert_suggestion_result("Is it correct that the output file seems to be the same of the input file a part from the format (input: jpg, output: png)?",APart::default(),"Is it correct that the output file seems to be the same of the input file apart from the format (input: jpg, output: png)?",@@ -135,7 +135,7 @@ mod tests {#[test]fn corrects_a_part_from_to_apart_from_english() {- assert_top3_suggestion_result(+ assert_suggestion_result("Do you know there are more languages out there a part from English right?",APart::default(),"Do you know there are more languages out there apart from English right?",@@ -144,7 +144,7 @@ mod tests {#[test]fn corrects_a_part_from_to_a_part_of() {- assert_top3_suggestion_result(+ assert_suggestion_result("An easy tool to generate backdoor with msfvenom (a part from metasploit framework).",APart::default(),"An easy tool to generate backdoor with msfvenom (a part of metasploit framework).",@@ -153,7 +153,7 @@ mod tests {#[test]fn corrects_apart_of_to_apart_from_cflinuxfs() {- assert_top3_suggestion_result(+ assert_suggestion_result("Doesn't work with any stacks apart of cflinuxfs2 and cflinuxfs3",APart::default(),"Doesn't work with any stacks apart from cflinuxfs2 and cflinuxfs3",@@ -162,7 +162,7 @@ mod tests {#[test]fn corrects_apart_of_to_apart_from_using() {- assert_top3_suggestion_result(+ assert_suggestion_result("apart of using filter, i can't find it in the documentation",APart::default(),"apart from using filter, i can't find it in the documentation",@@ -171,7 +171,7 @@ mod tests {#[test]fn corrects_apart_of_to_a_part_of_openai() {- assert_top3_suggestion_result(+ assert_suggestion_result("export 'Usage' class as apart of openai.types",APart::default(),"export 'Usage' class as a part of openai.types",@@ -180,7 +180,7 @@ mod tests {#[test]fn corrects_apart_of_to_a_part_of_formly() {- assert_top3_suggestion_result(+ assert_suggestion_result("FormlyDatepickerTypeComponent is not listed as apart of the Formly Public API",APart::default(),"FormlyDatepickerTypeComponent is not listed as a part of the Formly Public API",@@ -189,7 +189,7 @@ mod tests {#[test]fn corrects_far_a_part() {- assert_top3_suggestion_result(+ assert_suggestion_result("That leaves you only the other hand on the keyboard and you don't want the keys to be that far a part.",APart::default(),"That leaves you only the other hand on the keyboard and you don't want the keys to be that far apart.",@@ -198,7 +198,7 @@ mod tests {#[test]fn corrects_so_far_a_part_from_being_taken() {- assert_top3_suggestion_result(+ assert_suggestion_result("I can't see in the code what is done really with this session_timeout so far a part from being taken from the conf if defined there or setup ...",APart::default(),"I can't see in the code what is done really with this session_timeout so far apart from being taken from the conf if defined there or setup ...",@@ -207,7 +207,7 @@ mod tests {#[test]fn corrects_so_far_a_part_from_version_upgrade() {- assert_top3_suggestion_result(+ assert_suggestion_result("Any workaround so far a part from the version upgrade?",APart::default(),"Any workaround so far apart from the version upgrade?",@@ -216,7 +216,7 @@ mod tests {#[test]fn corrects_fall_a_part() {- assert_top3_suggestion_result(+ assert_suggestion_result("When I set up a script I set up card priority based on my frontline but sometimes a servant dies which sometimes causes things to fall a part.",APart::default(),"When I set up a script I set up card priority based on my frontline but sometimes a servant dies which sometimes causes things to fall apart.",diff --git a/harper-core/src/linting/after_later.rs b/harper-core/src/linting/after_later.rsindex 7d0fe7058..d158fb40e 100644--- a/harper-core/src/linting/after_later.rs+++ b/harper-core/src/linting/after_later.rs@@ -72,11 +72,11 @@ impl ExprLinter for AfterLater {#[cfg(test)]mod tests {use super::AfterLater;- use crate::linting::tests::assert_top3_suggestion_result;+ use crate::linting::tests::assert_suggestion_result;#[test]fn after_90_days_later() {- assert_top3_suggestion_result(+ assert_suggestion_result("Try to rename your organization after 90 days later because of GitHub official documentation it said.",AfterLater::default(),"Try to rename your organization after 90 days because of GitHub official documentation it said.",@@ -85,7 +85,7 @@ mod tests {#[test]fn after_about_30_minutes_later() {- assert_top3_suggestion_result(+ assert_suggestion_result("It plays like 1 minute of the song and then stops, and after about 30 minutes later, the bot disconnects an throws DisTubeError",AfterLater::default(),"It plays like 1 minute of the song and then stops, and about 30 minutes later, the bot disconnects an throws DisTubeError",@@ -94,7 +94,7 @@ mod tests {#[test]fn after_14_days_later() {- assert_top3_suggestion_result(+ assert_suggestion_result("After 14 days later, the cache expired.",AfterLater::default(),"After 14 days, the cache expired.",@@ -103,7 +103,7 @@ mod tests {#[test]fn after_exactly_5_minutes_later() {- assert_top3_suggestion_result(+ assert_suggestion_result("After exactly 5 minutes later, they try again and the cluster is formed then.",AfterLater::default(),"Exactly 5 minutes later, they try again and the cluster is formed then.",@@ -112,7 +112,7 @@ mod tests {#[test]fn after_22_years_later_1() {- assert_top3_suggestion_result(+ assert_suggestion_result("Completed YR campaign for 2nd time after 22 years later.",AfterLater::default(),"Completed YR campaign for 2nd time after 22 years.",@@ -121,7 +121,7 @@ mod tests {#[test]fn after_almost_2_years_later() {- assert_top3_suggestion_result(+ assert_suggestion_result("This buyer contacted me after almost 2 years later.",AfterLater::default(),"This buyer contacted me almost 2 years later.",@@ -130,7 +130,7 @@ mod tests {#[test]fn after_2_years_later() {- assert_top3_suggestion_result(+ assert_suggestion_result("Is Jedi Survivor better now after 2 years later?",AfterLater::default(),"Is Jedi Survivor better now after 2 years?",@@ -139,7 +139,7 @@ mod tests {#[test]fn after_a_year_later() {- assert_top3_suggestion_result(+ assert_suggestion_result("Even after a year later, I don’t know how to get my self-love back.",AfterLater::default(),"Even a year later, I don’t know how to get my self-love back.",@@ -148,7 +148,7 @@ mod tests {#[test]fn after_22_years_later_2() {- assert_top3_suggestion_result(+ assert_suggestion_result("After 22 years later, my top 1 game was Zeroed",AfterLater::default(),"After 22 years, my top 1 game was Zeroed",diff --git a/harper-core/src/linting/am_in_the_morning.rs b/harper-core/src/linting/am_in_the_morning.rsindex 1d76e5860..ddb248d30 100644--- a/harper-core/src/linting/am_in_the_morning.rs+++ b/harper-core/src/linting/am_in_the_morning.rs@@ -75,9 +75,7 @@ impl ExprLinter for AmInTheMorning {#[cfg(test)]mod tests {use super::AmInTheMorning;- use crate::linting::tests::{- assert_lint_count, assert_nth_suggestion_result, assert_suggestion_result,- };+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};#[test]fn flag_at_4am_in_the_morning() {@@ -150,11 +148,10 @@ mod tests {AmInTheMorning::default(),"I wrote this whole program as a joke, at 1 AM. Nothing else to say.",);- assert_nth_suggestion_result(+ assert_suggestion_result("I wrote this whole program as a joke, at 1 AM in the morning. Nothing else to say.",AmInTheMorning::default(),"I wrote this whole program as a joke, at 1 in the morning. Nothing else to say.",- 1,);}@@ -165,11 +162,10 @@ mod tests {AmInTheMorning::default(),"Luckily I was at home, but it was not fun at 3am.",);- assert_nth_suggestion_result(+ assert_suggestion_result("Luckily I was at home, but it was not fun at 3am in the morning.",AmInTheMorning::default(),"Luckily I was at home, but it was not fun at 3 in the morning.",- 1,);}@@ -180,11 +176,10 @@ mod tests {AmInTheMorning::default(),"If I want to run my script or some cron job at 3am, it seems to be not possible after macOS is in sleep mode.",);- assert_nth_suggestion_result(+ assert_suggestion_result("If I want to run my script or some cron job at 3am at night, it seems to be not possible after macOS is in sleep mode.",AmInTheMorning::default(),"If I want to run my script or some cron job at 3 at night, it seems to be not possible after macOS is in sleep mode.",- 1,);}@@ -195,11 +190,10 @@ mod tests {AmInTheMorning::default(),"The servers stop at 9PM and starts again at 9AM.",);- assert_nth_suggestion_result(+ assert_suggestion_result("The servers stop at 9PM at night and starts again at 9AM.",AmInTheMorning::default(),"The servers stop at 9 at night and starts again at 9AM.",- 1,);}@@ -210,11 +204,10 @@ mod tests {AmInTheMorning::default(),"Hello I can't believe my neighbor had the nerve to knock on my door at 3:30 AM.",);- assert_nth_suggestion_result(+ assert_suggestion_result("Hello I can't believe my neighbor had the nerve to knock on my door at 3:30 AM in the morning.",AmInTheMorning::default(),"Hello I can't believe my neighbor had the nerve to knock on my door at 3:30 in the morning.",- 1,);}@@ -225,11 +218,10 @@ mod tests {AmInTheMorning::default(),"Style issues get a blue marker: It's 5 P.M..",);- assert_nth_suggestion_result(+ assert_suggestion_result("Style issues get a blue marker: It's 5 P.M. in the afternoon.",AmInTheMorning::default(),"Style issues get a blue marker: It's 5 in the afternoon.",- 1,);}@@ -240,11 +232,10 @@ mod tests {AmInTheMorning::default(),"Its a impressively versatile tool if youd like to tell a colleague from over sea's about at 5 PM on Monday, 27 May 2007.",);- assert_nth_suggestion_result(+ assert_suggestion_result("Its a impressively versatile tool if youd like to tell a colleague from over sea's about at 5 PM in the afternoon on Monday, 27 May 2007.",AmInTheMorning::default(),"Its a impressively versatile tool if youd like to tell a colleague from over sea's about at 5 in the afternoon on Monday, 27 May 2007.",- 1,);}@@ -255,11 +246,10 @@ mod tests {AmInTheMorning::default(),"I am in China and it is six pm.",);- assert_nth_suggestion_result(+ assert_suggestion_result("I am in China and it is six pm in the evening.",AmInTheMorning::default(),"I am in China and it is six in the evening.",- 1,);}@@ -270,11 +260,10 @@ mod tests {AmInTheMorning::default(),"On the second application, we normally have the 503 between 1am and 4 am, almost every day.",);- assert_nth_suggestion_result(+ assert_suggestion_result("On the second application, we normally have the 503 between 1am and 4 am in the morning, almost every day.",AmInTheMorning::default(),"On the second application, we normally have the 503 between 1am and 4 in the morning, almost every day.",- 1,);}}diff --git a/harper-core/src/linting/amounts_for.rs b/harper-core/src/linting/amounts_for.rsindex c0c736cbf..25732b4b2 100644--- a/harper-core/src/linting/amounts_for.rs+++ b/harper-core/src/linting/amounts_for.rs@@ -95,11 +95,11 @@ impl ExprLinter for AmountsFor {#[cfg(test)]mod tests {use super::AmountsFor;- use crate::linting::tests::assert_top3_suggestion_result;+ use crate::linting::tests::assert_suggestion_result;#[test]fn corrects_that_amounts_for_to_amounts_to_entire_value() {- assert_top3_suggestion_result(+ assert_suggestion_result("Skyler stated the car wash is worth close to $800k, that amounts for the entire value of the company",AmountsFor::default(),"Skyler stated the car wash is worth close to $800k, that amounts to the entire value of the company",@@ -108,7 +108,7 @@ mod tests {#[test]fn corrects_that_amounts_for_to_amounts_to_percent() {- assert_top3_suggestion_result(+ assert_suggestion_result("Together, that amounts for 1157 calls or 60% of the failures.",AmountsFor::default(),"Together, that amounts to 1157 calls or 60% of the failures.",@@ -117,7 +117,7 @@ mod tests {#[test]fn corrects_that_amounts_for_to_accounts_for_setting_up() {- assert_top3_suggestion_result(+ assert_suggestion_result("One solution to this would be to have separate controllers but the amount of code that amounts for setting up, processing and calling",AmountsFor::default(),"One solution to this would be to have separate controllers but the amount of code that accounts for setting up, processing and calling",@@ -126,7 +126,7 @@ mod tests {#[test]fn corrects_which_amounts_for_to_accounts_for_16k() {- assert_top3_suggestion_result(+ assert_suggestion_result("It has an offset of 0xC000 which amounts for the 16k.",AmountsFor::default(),"It has an offset of 0xC000 which accounts for the 16k.",@@ -135,7 +135,7 @@ mod tests {#[test]fn corrects_this_amounts_for_to_accounts_for_large_part() {- assert_top3_suggestion_result(+ assert_suggestion_result("I'm pretty sure that this amounts for a large part of the speed I gained when typing, in addition to touch-typing.",AmountsFor::default(),"I'm pretty sure that this accounts for a large part of the speed I gained when typing, in addition to touch-typing.",@@ -144,7 +144,7 @@ mod tests {#[test]fn corrects_they_amount_for_to_amount_to_16kb() {- assert_top3_suggestion_result(+ assert_suggestion_result("it is obvious that the messages are being held \"somewhere\" until they amount for 16kB and then the whole lot come at once.",AmountsFor::default(),"it is obvious that the messages are being held \"somewhere\" until they amount to 16kB and then the whole lot come at once.",@@ -153,7 +153,7 @@ mod tests {#[test]fn corrects_which_amounts_for_to_amounts_to_10_minutes() {- assert_top3_suggestion_result(+ assert_suggestion_result("set a small TTL for your hostname (like 600 which amounts for 10 minutes).",AmountsFor::default(),"set a small TTL for your hostname (like 600 which amounts to 10 minutes).",@@ -162,7 +162,7 @@ mod tests {#[test]fn corrects_it_amounts_for_to_amounts_to_redefinition() {- assert_top3_suggestion_result(+ assert_suggestion_result("included for convenience to get a Lorentz invariant result (it amounts for a redefinition of ap).",AmountsFor::default(),"included for convenience to get a Lorentz invariant result (it amounts to a redefinition of ap).",@@ -171,7 +171,7 @@ mod tests {#[test]fn corrects_they_amount_for_to_amount_to_nothing() {- assert_top3_suggestion_result(+ assert_suggestion_result("Matter and antimatter are spread throughout the Universe, and in total, they amount for nothing",AmountsFor::default(),"Matter and antimatter are spread throughout the Universe, and in total, they amount to nothing",@@ -180,7 +180,7 @@ mod tests {#[test]fn would_amount_for_to_amount_to_api_requests() {- assert_top3_suggestion_result(+ assert_suggestion_result("10% of 6,782,091 would amount for 678,209 API requests",AmountsFor::default(),"10% of 6,782,091 would amount to 678,209 API requests",@@ -189,7 +189,7 @@ mod tests {#[test]fn will_amount_for_to_amount_to_relationships() {- assert_top3_suggestion_result(+ assert_suggestion_result("Consider this statistic from Gartner, that artificial intelligence will amount for 85% of customer relationships by 2020.",AmountsFor::default(),"Consider this statistic from Gartner, that artificial intelligence will amount to 85% of customer relationships by 2020.",@@ -198,7 +198,7 @@ mod tests {#[test]fn should_amount_for_to_amount_to_half_pack() {- assert_top3_suggestion_result(+ assert_suggestion_result("It doesn't seem realistic that this single elite should amount for half the pack",AmountsFor::default(),"It doesn't seem realistic that this single elite should amount to half the pack",@@ -207,7 +207,7 @@ mod tests {#[test]fn can_amount_for_to_amount_to_draw_calls() {- assert_top3_suggestion_result(+ assert_suggestion_result("That can amount for a lot of draw calls and work for the engine to cull. ",AmountsFor::default(),"That can amount to a lot of draw calls and work for the engine to cull. ",diff --git a/harper-core/src/linting/avoid_curses.rs b/harper-core/src/linting/avoid_curses.rsindex c68315fad..b841eb92a 100644--- a/harper-core/src/linting/avoid_curses.rs+++ b/harper-core/src/linting/avoid_curses.rs@@ -251,7 +251,7 @@ impl ExprLinter for AvoidCurses {#[cfg(test)]mod tests {use super::AvoidCurses;- use crate::linting::tests::{assert_lint_count, assert_top3_suggestion_result};+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};#[test]fn detects_shit() {@@ -264,22 +264,22 @@ mod tests {#[test]fn fix_shit() {- assert_top3_suggestion_result("shit", AvoidCurses::default(), "crap")+ assert_suggestion_result("shit", AvoidCurses::default(), "crap")}#[test]fn fix_shit_titlecase() {- assert_top3_suggestion_result("Shit", AvoidCurses::default(), "Crap")+ assert_suggestion_result("Shit", AvoidCurses::default(), "Crap")}#[test]fn fix_shit_allcaps() {- assert_top3_suggestion_result("SHIT", AvoidCurses::default(), "CRAP")+ assert_suggestion_result("SHIT", AvoidCurses::default(), "CRAP")}#[test]fn fix_f_word_to_all_asterisks() {- assert_top3_suggestion_result(+ assert_suggestion_result("fuck those fucking fuckers",AvoidCurses::default(),"**** those ****ing ****ers",@@ -288,11 +288,11 @@ mod tests {#[test]fn fix_shit_with_single_asterisk() {- assert_top3_suggestion_result("shit", AvoidCurses::default(), "sh*t")+ assert_suggestion_result("shit", AvoidCurses::default(), "sh*t")}#[test]fn fix_shite_all_caps_with_single_asterisk() {- assert_top3_suggestion_result("SHIT", AvoidCurses::default(), "SH*T")+ assert_suggestion_result("SHIT", AvoidCurses::default(), "SH*T")}}diff --git a/harper-core/src/linting/currency_placement.rs b/harper-core/src/linting/currency_placement.rsindex 1566747db..a89317c2e 100644--- a/harper-core/src/linting/currency_placement.rs+++ b/harper-core/src/linting/currency_placement.rs@@ -62,7 +62,9 @@ fn generate_lint_for_tokens(a: &Token, b: &Token, document: &Document) -> Option#[cfg(test)]mod tests {- use crate::linting::tests::{assert_lint_count, assert_suggestion_result};+ use crate::linting::tests::{+ assert_lint_count, assert_markdown_suggestion_result, assert_suggestion_result,+ };use super::CurrencyPlacement;@@ -108,14 +110,23 @@ mod tests {}#[test]- fn multiple_dollar() {- assert_suggestion_result(+ fn multiple_dollar_markdown() {+ assert_markdown_suggestion_result("They were either 25\\$ 24\\$ or 23\\$.",CurrencyPlacement::default(),"They were either $25 $24 or $23.",);}+ #[test]+ fn multiple_dollar_plain_english() {+ assert_suggestion_result(+ "They were either 25$ 24$ or 23$.",+ CurrencyPlacement::default(),+ "They were either $25 $24 or $23.",+ );+ }+#[test]fn multiple_pound() {assert_suggestion_result(diff --git a/harper-core/src/linting/everyday.rs b/harper-core/src/linting/everyday.rsindex c0df3bded..75e69a225 100644--- a/harper-core/src/linting/everyday.rs+++ b/harper-core/src/linting/everyday.rs@@ -190,9 +190,7 @@ impl ExprLinter for Everyday {#[cfg(test)]mod tests {use super::Everyday;- use crate::linting::tests::{- assert_lint_count, assert_no_lints, assert_suggestion_result, assert_top3_suggestion_result,- };+ use crate::linting::tests::{assert_lint_count, assert_no_lints, assert_suggestion_result};#[test]fn dont_flag_lone_adjective() {@@ -358,7 +356,7 @@ mod tests {#[test]fn fix_everyday_and_every_day_used_wrongly() {- assert_top3_suggestion_result(+ assert_suggestion_result("Each and everyday you ought to strive to learn something that is not an every day thing.",Everyday::default(),"Each and every day you ought to strive to learn something that is not an everyday thing.",@@ -367,7 +365,7 @@ mod tests {#[test]fn fix_reddit_why_does_everyday() {- assert_top3_suggestion_result(+ assert_suggestion_result("Why does everyday feel the same?",Everyday::default(),"Why does every day feel the same?",@@ -376,7 +374,7 @@ mod tests {#[test]fn fix_reddit_everyday_is_going_to() {- assert_top3_suggestion_result(+ assert_suggestion_result("... everyday is going to be a good day that's just the way it is!",Everyday::default(),"... every day is going to be a good day that's just the way it is!",@@ -385,7 +383,7 @@ mod tests {#[test]fn fix_reddit_draw_everyday() {- assert_top3_suggestion_result(+ assert_suggestion_result("Do you actually improve if you draw everyday?",Everyday::default(),"Do you actually improve if you draw every day?",@@ -394,7 +392,7 @@ mod tests {#[test]fn fix_reddit_two_bad_out_of_three() {- assert_top3_suggestion_result(+ assert_suggestion_result("Yes you can jog everyday, not a personal best every day, but a steady pace run everyday.",Everyday::default(),"Yes you can jog every day, not a personal best every day, but a steady pace run every day.",@@ -403,7 +401,7 @@ mod tests {#[test]fn fix_reddit_every_day_routine() {- assert_top3_suggestion_result(+ assert_suggestion_result("Habit stacking - stacking the small skill with something that's already worked into my every day routine.",Everyday::default(),"Habit stacking - stacking the small skill with something that's already worked into my everyday routine.",@@ -412,7 +410,7 @@ mod tests {#[test]fn fix_stackoverflow_every_day_things() {- assert_top3_suggestion_result(+ assert_suggestion_result("However, the message goes far beyond every day things.",Everyday::default(),"However, the message goes far beyond everyday things.",@@ -421,7 +419,7 @@ mod tests {#[test]fn fix_reddit_everyday_is_same() {- assert_top3_suggestion_result(+ assert_suggestion_result("Everyday is exactly the same",Everyday::default(),"Every day is exactly the same",@@ -431,7 +429,7 @@ mod tests {#[test]#[ignore = "doesn't work yet because title case demands 'Every Day' but we get 'Every day'"]fn fix_medium_little_bit_everyday() {- assert_top3_suggestion_result(+ assert_suggestion_result("Does Learning A Little Bit Everyday Actually Work?",Everyday::default(),"Does Learning A Little Bit Every Day Actually Work?",@@ -440,7 +438,7 @@ mod tests {#[test]fn fix_stackexchange_use_everyday() {- assert_top3_suggestion_result(+ assert_suggestion_result("We use this everyday without noticing, but we hate it when ...",Everyday::default(),"We use this every day without noticing, but we hate it when ...",@@ -449,7 +447,7 @@ mod tests {#[test]fn fix_github_what_i_learned_everyday() {- assert_top3_suggestion_result(+ assert_suggestion_result("Trying to write about what I learned everyday.",Everyday::default(),"Trying to write about what I learned every day.",@@ -458,7 +456,7 @@ mod tests {#[test]fn fix_medium_one_bad_out_of_three() {- assert_top3_suggestion_result(+ assert_suggestion_result("Even inside a routine, everyday we adapt to changes and challenges ... We are not the same person every day, but every day we are ourselves…",Everyday::default(),"Even inside a routine, every day we adapt to changes and challenges ... We are not the same person every day, but every day we are ourselves…",@@ -467,7 +465,7 @@ mod tests {#[test]fn fix_medium_doing_something_everyday() {- assert_top3_suggestion_result(+ assert_suggestion_result("There was nothing wrong with my braincells processing the concepts of doing something everyday and ...",Everyday::default(),"There was nothing wrong with my braincells processing the concepts of doing something every day and ...",@@ -476,7 +474,7 @@ mod tests {#[test]fn fix_medium_all_caps() {- assert_top3_suggestion_result(+ assert_suggestion_result("MEET SOMEONE NEW EVERYDAY.",Everyday::default(),"MEET SOMEONE NEW EVERY DAY.",diff --git a/harper-core/src/linting/few_units_of_time_ago.rs b/harper-core/src/linting/few_units_of_time_ago.rsindex 590d02036..05d46018d 100644--- a/harper-core/src/linting/few_units_of_time_ago.rs+++ b/harper-core/src/linting/few_units_of_time_ago.rs@@ -67,9 +67,7 @@ impl ExprLinter for FewUnitsOfTimeAgo {#[cfg(test)]mod tests {use super::*;- use crate::linting::tests::{- assert_lint_count, assert_suggestion_result, assert_top3_suggestion_result,- };+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};// Basic unit tests@@ -90,7 +88,7 @@ mod tests {#[test]fn fix_done_few_minutes_ago() {- assert_top3_suggestion_result(+ assert_suggestion_result("Done few minutes ago",FewUnitsOfTimeAgo::default(),"Done a few minutes ago",diff --git a/harper-core/src/linting/lead_rise_to.rs b/harper-core/src/linting/lead_rise_to.rsindex d81bec202..a349fbe17 100644--- a/harper-core/src/linting/lead_rise_to.rs+++ b/harper-core/src/linting/lead_rise_to.rs@@ -71,7 +71,7 @@ impl ExprLinter for LeadRiseTo {#[cfg(test)]mod tests {use super::LeadRiseTo;- use crate::linting::tests::{assert_suggestion_result, assert_top3_suggestion_result};+ use crate::linting::tests::assert_suggestion_result;#[test]fn fix_led_simple_past() {@@ -84,7 +84,7 @@ mod tests {#[test]fn fix_led_past_participle() {- assert_top3_suggestion_result(+ assert_suggestion_result("This had led rise to some issues, such as #2777 and some over Slack",LeadRiseTo::default(),"This had given rise to some issues, such as #2777 and some over Slack",@@ -93,7 +93,7 @@ mod tests {#[test]fn fix_lead_spello_for_led() {- assert_top3_suggestion_result(+ assert_suggestion_result("This lead rise to a fair number of complaints over image quality which were not down to RPT.",LeadRiseTo::default(),"This gave rise to a fair number of complaints over image quality which were not down to RPT.",diff --git a/harper-core/src/linting/less_worse.rs b/harper-core/src/linting/less_worse.rsindex 26f6f51fc..dda943501 100644--- a/harper-core/src/linting/less_worse.rs+++ b/harper-core/src/linting/less_worse.rs@@ -100,7 +100,7 @@ impl ExprLinter for LessWorse {#[cfg(test)]mod tests {- use crate::linting::tests::{assert_good_and_bad_suggestions, assert_top3_suggestion_result};+ use crate::linting::tests::{assert_good_and_bad_suggestions, assert_suggestion_result};use super::LessWorse;@@ -133,7 +133,7 @@ mod tests {#[test]fn correct_less_worse() {- assert_top3_suggestion_result(+ assert_suggestion_result("Professionally I've convinced the team at @Roave to pay me for making their PHP code marginally less worse.",LessWorse::default(),"Professionally I've convinced the team at @Roave to pay me for making their PHP code marginally less bad.",diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rsindex ddfa8058d..1a7c3ad7c 100644--- a/harper-core/src/linting/lint_group.rs+++ b/harper-core/src/linting/lint_group.rs@@ -176,6 +176,7 @@ use super::redundant_acronyms::RedundantAcronyms;use super::redundant_additive_adverbs::RedundantAdditiveAdverbs;use super::redundant_progressive_comparative::RedundantProgressiveComparative;use super::regionalisms::Regionalisms;+use super::regular_irregulars::RegularIrregulars;use super::repeated_words::RepeatedWords;use super::respond::Respond;use super::right_click::RightClick;@@ -759,6 +760,7 @@ impl LintGroup {insert_expr_rule!(RedundantAdditiveAdverbs, true);insert_expr_rule!(RedundantProgressiveComparative, true);insert_struct_rule_with_dialect!(Regionalisms, true);+ insert_expr_rule_with_dict!(RegularIrregulars, true);insert_struct_rule!(RepeatedWords, true);insert_expr_rule!(Respond, true);insert_expr_rule!(RightClick, true);diff --git a/harper-core/src/linting/mass_nouns/noun_countability.rs b/harper-core/src/linting/mass_nouns/noun_countability.rsindex 8916b51da..89a5572d4 100644--- a/harper-core/src/linting/mass_nouns/noun_countability.rs+++ b/harper-core/src/linting/mass_nouns/noun_countability.rs@@ -202,11 +202,11 @@ impl ExprLinter for NounCountability {#[cfg(test)]mod tests {use super::NounCountability;- use crate::linting::tests::{assert_lint_count, assert_top3_suggestion_result};+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};#[test]fn corrects_a() {- assert_top3_suggestion_result(+ assert_suggestion_result("If the unit turns out to be noisy, can I expect a firmware with phase ...",NounCountability::default(),"If the unit turns out to be noisy, can I expect some firmware with phase ...",@@ -216,7 +216,7 @@ mod tests {#[test]#[ignore = "replace_with_match_case matches by index, not by lower vs title vs upper"]fn corrects_a_title_case() {- assert_top3_suggestion_result(+ assert_suggestion_result("Simple POC of a Ransomware.",NounCountability::default(),"Simple POC of a piece of Ransomware.",@@ -225,7 +225,7 @@ mod tests {#[test]fn corrects_an() {- assert_top3_suggestion_result(+ assert_suggestion_result("The PlaySEM platform provides an infrastructure for playing and rendering sensory effects in multimedia applications.",NounCountability::default(),"The PlaySEM platform provides infrastructure for playing and rendering sensory effects in multimedia applications.",@@ -235,7 +235,7 @@ mod tests {#[test]#[ignore = "replace_with_match_case matches by index, not by lower vs title vs upper"]fn corrects_an_title_case() {- assert_top3_suggestion_result(+ assert_suggestion_result("An Infrastructure for Integrated EDA.",NounCountability::default(),"Infrastructure for Integrated EDA.",@@ -244,7 +244,7 @@ mod tests {#[test]fn corrects_another() {- assert_top3_suggestion_result(+ assert_suggestion_result("Another ransomware made by me for fun.",NounCountability::default(),"Another piece of ransomware made by me for fun.",@@ -253,7 +253,7 @@ mod tests {#[test]fn corrects_both() {- assert_top3_suggestion_result(+ assert_suggestion_result("Make a terminal show both information of your CPU and GPU!",NounCountability::default(),"Make a terminal show both pieces of information of your CPU and GPU!",@@ -263,7 +263,7 @@ mod tests {#[test]// "piece of traffic" sounds very weirdfn can_correct_each_with_traffic() {- assert_top3_suggestion_result(+ assert_suggestion_result("Beside each traffic there is also a pedestrian traffic light.",NounCountability::default(),"Beside each traffic there is also a pedestrian traffic light.",@@ -272,7 +272,7 @@ mod tests {#[test]fn corrects_every() {- assert_top3_suggestion_result(+ assert_suggestion_result("Capacitor plugin to get access to every info about the device software and hardware.",NounCountability::default(),"Capacitor plugin to get access to every piece of info about the device software and hardware.",@@ -281,7 +281,7 @@ mod tests {#[test]fn corrects_few() {- assert_top3_suggestion_result(+ assert_suggestion_result("Displays a few information to help you rotating through your spells.",NounCountability::default(),"Displays a few pieces of information to help you rotating through your spells.",@@ -290,7 +290,7 @@ mod tests {#[test]fn corrects_many() {- assert_top3_suggestion_result(+ assert_suggestion_result("It shows clearly how many information about objects you can get with old search ...",NounCountability::default(),"It shows clearly how much information about objects you can get with old search ...",@@ -299,7 +299,7 @@ mod tests {#[test]fn corrects_one() {- assert_top3_suggestion_result(+ assert_suggestion_result("For example, it only makes sense to compare global protein q-value filtering in one software with that in another.",NounCountability::default(),"For example, it only makes sense to compare global protein q-value filtering in one application with that in another.",@@ -309,7 +309,7 @@ mod tests {#[test]#[ignore = "'in' = noun because conflated with 'IN' (Indiana)"]fn corrects_several() {- assert_top3_suggestion_result(+ assert_suggestion_result("The program takes in input a single XML file and outputs several info in different files.",NounCountability::default(),"The program takes in input a single XML file and outputs several pieces of info in different files.",@@ -328,7 +328,7 @@ mod tests {#[test]#[ignore]fn dont_correct_first_do_correct_second() {- assert_top3_suggestion_result(+ assert_suggestion_result("A advice description is required for each advice.",NounCountability::default(),"A advice description is required for each piece of advice.",@@ -337,7 +337,7 @@ mod tests {#[test]fn corrects_an_advice() {- assert_top3_suggestion_result(+ assert_suggestion_result("Origin will not always provide the right method when an advice is applied to a bridged method.",NounCountability::default(),"Origin will not always provide the right method when an tip is applied to a bridged method.",@@ -346,7 +346,7 @@ mod tests {#[test]fn corrects_one_advice() {- assert_top3_suggestion_result(+ assert_suggestion_result("Is it possible to use more than one advice on the same method?",NounCountability::default(),"Is it possible to use more than one tip on the same method?",@@ -355,7 +355,7 @@ mod tests {#[test]fn corrects_every_advice() {- assert_top3_suggestion_result(+ assert_suggestion_result("Ideally every advice would have a unique identifier.",NounCountability::default(),"Ideally every tip would have a unique identifier.",@@ -364,7 +364,7 @@ mod tests {#[test]fn corrects_a_advice() {- assert_top3_suggestion_result(+ assert_suggestion_result("Hello! I need a advice.",NounCountability::default(),"Hello! I need a tip.",@@ -373,7 +373,7 @@ mod tests {#[test]fn corrects_a_software() {- assert_top3_suggestion_result(+ assert_suggestion_result("HGroup-DIA, a software for analyzing multiple DIA data files.",NounCountability::default(),"HGroup-DIA, a software package for analyzing multiple DIA data files.",@@ -382,7 +382,7 @@ mod tests {#[test]fn corrects_a_luggage() {- assert_top3_suggestion_result(+ assert_suggestion_result("A luggage with a little engine, sensors (gps, ultrasounds, etc...) and bluetooth connection that will follow you everywhere.",NounCountability::default(),"A suitcase with a little engine, sensors (gps, ultrasounds, etc...) and bluetooth connection that will follow you everywhere.",@@ -391,7 +391,7 @@ mod tests {#[test]fn corrects_multiple_advice() {- assert_top3_suggestion_result(+ assert_suggestion_result("Update Advice API doc for event and data params, multiple advice.",NounCountability::default(),"Update Advice API doc for event and data params, multiple suggestions.",@@ -400,7 +400,7 @@ mod tests {#[test]fn corrects_every_software() {- assert_top3_suggestion_result(+ assert_suggestion_result("Rewrite every software known to man in Rust.",NounCountability::default(),"Rewrite every application known to man in Rust.",@@ -409,7 +409,7 @@ mod tests {#[test]fn corrects_each_furniture() {- assert_top3_suggestion_result(+ assert_suggestion_result("the position (x, y) and size (height, width, length) of each furniture",NounCountability::default(),"the position (x, y) and size (height, width, length) of each piece of furniture",@@ -418,7 +418,7 @@ mod tests {#[test]fn corrects_one_clothing() {- assert_top3_suggestion_result(+ assert_suggestion_result("Each list element represents one clothing based on weather conditions.",NounCountability::default(),"Each list element represents one garment based on weather conditions.",@@ -451,7 +451,7 @@ mod tests {#[test]fn corrects_fewer() {- assert_top3_suggestion_result(+ assert_suggestion_result("Why do my packages have fewer information?",NounCountability::default(),"Why do my packages have less information?",@@ -478,7 +478,7 @@ mod tests {#[test]fn corrects_punctuation() {- assert_top3_suggestion_result(+ assert_suggestion_result("Not in this form because it currently works with one punctuation with one letter either side.",NounCountability::default(),"Not in this form because it currently works with one punctuation mark with one letter either side.",diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex f91339860..0b7af3e9d 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -185,6 +185,7 @@ mod redundant_acronyms;mod redundant_additive_adverbs;mod redundant_progressive_comparative;mod regionalisms;+mod regular_irregulars;mod repeated_words;mod respond;mod right_click;@@ -337,8 +338,7 @@ pub mod debug {#[cfg(test)]pub mod tests {- use crate::parsers::Markdown;- use crate::{Document, Span, Token};+ use crate::{Document, Span, Token, linting::Linter};use hashbrown::HashSet;/// Extension trait for converting spans of tokens back to their original text@@ -359,17 +359,116 @@ pub mod tests {}}- use super::Linter;- use crate::spell::FstDictionary;+ // Special Linter just for testing+ use crate::{+ CharStringExt, Lint, TokenStringExt,+ linting::{LintKind, Suggestion},+ };++ /// Type alias for many:many error-to-fix mappings used in testing+ /// Each error pattern can map to multiple possible fixes+ pub type TestLinterMap<'a> = &'a [(&'a [&'a str], &'a [&'a str])];++ #[derive(Clone)]+ pub struct TestLinter<'a> {+ map: TestLinterMap<'a>,+ }+ impl<'a> TestLinter<'a> {+ pub fn new(map: TestLinterMap<'a>) -> Self {+ Self { map }+ }+ }+ impl<'a> Linter for TestLinter<'a> {+ fn lint(&mut self, doc: &Document) -> Vec<Lint> {+ let mut corr: Vec<(Span<char>, &[char], &[&str])> = Vec::new();+ for wordtok in doc.iter_words() {+ let wordspan = wordtok.span;+ let word_chars = wordspan.get_content(doc.get_source());+ // Check if word matches any of the patterns in the map+ for (errors, fixes) in self.map {+ // if any of the errors match, add all of the corrections+ if errors+ .iter()+ .any(|&e| word_chars.eq_ignore_ascii_case_str(e))+ {+ corr.push((wordspan, word_chars, fixes))+ }+ }+ }+ corr.iter()+ .map(|(ws, wch, cstr)| {+ // Create suggestions for all possible fixes+ let suggestions: Vec<Suggestion> = cstr+ .iter()+ .map(|&suggestion_str| {+ Suggestion::replace_with_match_case(+ suggestion_str.chars().collect(),+ wch.to_owned(),+ )+ })+ .collect();++ Lint {+ span: *ws,+ lint_kind: LintKind::Spelling,+ suggestions,+ message: "Test linter for 'linting assertion' tests".to_string(),+ ..Default::default()+ }+ })+ .collect()+ }+ fn description(&self) -> &str {+ "Test linter for 'linting assertion' tests"+ }+ }++ // Before the asserts, let's test that the test linter itself has the behaviours we intend+ mod linter_tests {+ use super::{TestLinter, assert_suggestion_result};++ #[test]+ fn test_1_to_1_error_to_fix() {+ assert_suggestion_result("bad", TestLinter::new(&[(&["bad"], &["good"])]), "good");+ }++ #[test]+ fn test_1_to_2_error_to_fixes() {+ let linter = TestLinter::new(&[(&["bad"], &["good1", "good2"])]);+ assert_suggestion_result("bad", linter.clone(), "good1");+ assert_suggestion_result("bad", linter, "good2");+ }++ #[test]+ fn test_2_to_1_errors_to_fix() {+ let linter = TestLinter::new(&[(&["bad1", "bad2"], &["good"])]);+ assert_suggestion_result("bad1", linter.clone(), "good");+ assert_suggestion_result("bad2", linter, "good");+ }++ #[test]+ fn test_2_to_2_errors_to_fixes() {+ let linter = TestLinter::new(&[(&["bad1", "bad2"], &["good1", "good2"])]);+ assert_suggestion_result("bad1", linter.clone(), "good1");+ assert_suggestion_result("bad2", linter.clone(), "good2");+ assert_suggestion_result("bad1", linter.clone(), "good2");+ assert_suggestion_result("bad2", linter, "good1");+ }+ }#[track_caller]pub fn assert_no_lints(text: &str, linter: impl Linter) {assert_lint_count(text, linter, 0);}+ #[test]+ fn verify_no_lints() {+ assert_no_lints("hello world", TestLinter::new(&[]));+ }+#[track_caller]pub fn assert_lint_count(text: &str, mut linter: impl Linter, count: usize) {- let test = Document::new_markdown_default_curated(text);+ let test = Document::new_plain_english_curated(text);let lints = linter.lint(&test);// dbg!(&lints);if lints.len() != count {@@ -380,75 +479,189 @@ pub mod tests {}}+ #[test]+ fn verify_1_lint() {+ assert_lint_count(+ "heloo world",+ TestLinter::new(&[(&["heloo"], &["hello"])]),+ 1,+ );+ }++ #[test]+ fn verify_2_lints() {+ assert_lint_count(+ "heloo wolrd",+ TestLinter::new(&[(&["heloo"], &["hello"]), (&["wolrd"], &["world"])]),+ 2,+ );+ }+/// Assert the total number of suggestions produced by a [`Linter`], spread across all produced/// [`Lint`]s.#[track_caller]pub fn assert_suggestion_count(text: &str, mut linter: impl Linter, count: usize) {- let test = Document::new_markdown_default_curated(text);+ let test = Document::new_plain_english_curated(text);let lints = linter.lint(&test);+ eprintln!(+ "{}",+ lints+ .iter()+ .map(|l| l+ .suggestions+ .iter()+ .map(|s| s.to_string())+ .collect::<Vec<_>>()+ .join(", "))+ .collect::<Vec<_>>()+ .join("\n")+ );assert_eq!(lints.iter().map(|l| l.suggestions.len()).sum::<usize>(),count);}- /// Runs a provided linter on text, applies the first suggestion from each lint- /// and asserts whether the result is equal to a given value.- #[track_caller]- pub fn assert_suggestion_result(text: &str, linter: impl Linter, expected_result: &str) {- assert_nth_suggestion_result(text, linter, expected_result, 0);+ #[test]+ fn verify_no_suggestions() {+ assert_suggestion_count("afjehwkf", TestLinter::new(&[]), 0);+ }++ #[test]+ fn verify_1_suggestion() {+ assert_suggestion_count(+ "dictionery",+ TestLinter::new(&[(&["dictionery"], &["dictionary"])]),+ 1,+ );+ }++ /// Document types for suggestion search testing+ #[derive(Debug, Clone, Copy)]+ enum DocumentType {+ PlainEnglish,+ Markdown,+ }++ /// Creates a document of the specified type from character data+ fn create_document(chars: &[char], doc_type: DocumentType) -> Document {+ match doc_type {+ DocumentType::PlainEnglish => Document::new_plain_english_curated_chars(chars),+ DocumentType::Markdown => Document::new_markdown_default_curated_chars(chars),+ }}- /// Runs a provided linter on text, applies the nth suggestion from each lint- /// and asserts whether the result is equal to a given value.+ /// Applies suggestions iteratively until any combination produces the expected result.+ ///+ /// Explores all possible suggestion branches (depth-first search) until finding a path+ /// that produces the expected result. Stops after 100 iterations to prevent infinite loops.///- /// Note that `n` starts at zero.+ /// Use this when you want to verify that *some* suggestion sequence produces the+ /// expected result, without caring which specific suggestions are used.+ ///+ /// See issue #950: https://github.com/Automattic/harper/issues/950#[track_caller]- pub fn assert_nth_suggestion_result(- text: &str,- mut linter: impl Linter,- expected_result: &str,- n: usize,- ) {- let transformed_str = transform_nth_str(text, &mut linter, n);-- if transformed_str.as_str() != expected_result {- panic!("Expected \"{expected_result}\"\n But got \"{transformed_str}\"");+ pub fn assert_suggestion_result(text: &str, mut linter: impl Linter, needle: &str) {+ if search_for_suggestion(DocumentType::PlainEnglish, text, &mut linter, needle, 0) {+ return;}- // Applying the suggestions should fix all the lints.- assert_lint_count(&transformed_str, linter, 0);+ panic!(+ "No suggestion sequence produced the expected result.\n\+ Expected: \"{needle}\""+ );}+ /// DFS implementation using markdown instead of plain English#[track_caller]- pub fn assert_top3_suggestion_result(+ pub fn assert_markdown_suggestion_result(text: &str, mut linter: impl Linter, needle: &str) {+ if !search_for_suggestion(DocumentType::Markdown, text, &mut linter, needle, 0) {+ panic!("No suggestion sequence produced the expected result.\nExpected: {needle}");+ }+ }++ /// Recursively searches all suggestion combinations using depth-first search.+ /// Returns true if any path reaches the expected result, false otherwise.+ fn search_for_suggestion(+ doc_type: DocumentType,text: &str,- mut linter: impl Linter,- expected_result: &str,- ) {- let zeroth = transform_nth_str(text, &mut linter, 0);- let first = transform_nth_str(text, &mut linter, 1);- let second = transform_nth_str(text, &mut linter, 2);-- match (- zeroth.as_str() == expected_result,- first.as_str() == expected_result,- second.as_str() == expected_result,- ) {- (true, false, false) => assert_lint_count(&zeroth, linter, 0),- (false, true, false) => assert_lint_count(&first, linter, 0),- (false, false, true) => assert_lint_count(&second, linter, 0),- (false, false, false) => panic!(- "None of the top 3 suggestions produced the expected result:\n\- Expected: \"{expected_result}\"\n\- Got:\n\- [0]: \"{zeroth}\"\n\- [1]: \"{first}\"\n\- [2]: \"{second}\""- ),- // I think it's not possible for more than one suggestion to be correct- _ => {}+ linter: &mut impl Linter,+ needle: &str,+ depth: usize,+ ) -> bool {+ // Prevent infinite recursion (e.g. cycles in suggestions)+ if depth > 100 {+ eprintln!("⚠️ Reached depth limit (100)");+ return false;}++ // Check if we've reached the expected result+ if text == needle {+ return true;+ }++ // Lint current text and try each suggestion branch+ let chars: Vec<char> = text.chars().collect();+ let document = create_document(&chars, doc_type);+ let lints = linter.lint(&document);++ if let Some(lint) = lints.first() {+ for sug in lint.suggestions.iter() {+ let mut chars_copy = chars.clone();+ sug.apply(lint.span, &mut chars_copy);+ let next: String = chars_copy.iter().collect();++ // Recursively search this branch+ if search_for_suggestion(doc_type, &next, linter, needle, depth + 1) {+ return true;+ }+ }+ }++ false+ }++ #[test]+ fn verify_fix_one_lint() {+ assert_suggestion_result(+ "find the misstake and fix it",+ TestLinter::new(&[(&["misstake"], &["mistake"])]),+ "find the mistake and fix it",+ );+ }++ #[test]+ #[should_panic]+ fn verify_unable_to_fix_one_spanish_lint() {+ assert_suggestion_result("Hay una orrrer", TestLinter::new(&[]), "Hay una error");+ }++ #[test]+ fn verify_fix_two_lints() {+ assert_suggestion_result(+ "find two misstakes and fix theem",+ TestLinter::new(&[(&["misstakes"], &["mistakes"]), (&["theem"], &["them"])]),+ "find two mistakes and fix them",+ );+ }++ // Stress test: multiple errors in one sentence, DFS must find correct suggestion path+ // Note: This test is known to be brittle - it depends on SpellCheck dictionary and+ // suggestion ranking. If it fails after a dictionary update, try different word combinations.+ // Uses common misspellings that have unambiguous correct suggestions in the top 3.+ #[test]+ fn verify_fix_five_typos() {+ assert_suggestion_result(+ "Please recieve teh payment untill thier authorization occured",+ TestLinter::new(&[+ (&["recieve"], &["receive"]),+ (&["teh"], &["the"]),+ (&["untill"], &["until"]),+ (&["thier"], &["their"]),+ (&["occured"], &["occurred"]),+ ]),+ "Please receive the payment until their authorization occurred",+ );}/// Asserts that none of the suggestions from the linter match the given text.@@ -458,28 +671,49 @@ pub mod tests {mut linter: impl Linter,bad_suggestion: &str,) {- let test = Document::new_markdown_default_curated(text);- let lints = linter.lint(&test);+ if !search_for_suggestion(+ DocumentType::PlainEnglish,+ text,+ &mut linter,+ bad_suggestion,+ 0,+ ) {+ return;+ }- for (i, lint) in lints.iter().enumerate() {- for (j, suggestion) in lint.suggestions.iter().enumerate() {- let mut text_chars: Vec<char> = text.chars().collect();- suggestion.apply(lint.span, &mut text_chars);- let suggestion_text: String = text_chars.into_iter().collect();+ panic!(+ "A suggestion sequence produced the undesired result.\n\+ Undesired: \"{bad_suggestion}\""+ );+ }- if suggestion_text == bad_suggestion {- panic!(- "Found undesired suggestion at lint[{i}].suggestions[{j}]:\n\- Expected to not find suggestion: \"{bad_suggestion}\"\n\- But found: \"{suggestion_text}\""- );- }- }- }+ #[test]+ fn verify_sole_suggestion_is_the_one_we_wanted() {+ assert_not_in_suggestion_result(+ "Baby cats are called kitens",+ TestLinter::new(&[]),+ "Baby cats are called puppies",+ );+ }++ // TODO verify sole suggestion is not the one we wanted fails++ #[test]+ #[should_panic]+ fn verify_sole_suggestion_not_in_result_fails() {+ assert_not_in_suggestion_result(+ "heloo",+ TestLinter::new(&[(&["heloo"], &["hello"])]),+ "hello",+ );}+ // TODO verify many suggestions including the one we want succeeds+ // TODO verify many suggestions but not the one we want fails+/// Asserts both that the given text matches the expected good suggestions and that none of the/// suggestions are in the bad suggestions list.+ /// TODO: Reimplement similar to `search_suggestion_tree`#[track_caller]pub fn assert_good_and_bad_suggestions(text: &str,@@ -487,7 +721,7 @@ pub mod tests {good: &[&str],bad: &[&str],) {- let test = Document::new_markdown_default_curated(text);+ let test = Document::new_plain_english_curated(text);let lints = linter.lint(&test);let mut unseen_good: HashSet<_> = good.iter().cloned().collect();@@ -555,13 +789,27 @@ pub mod tests {}}+ // TODO test that having all the good and none of the bad succeeds+ // TODO test that missing one of the good fails+ // TODO test that having one of the bads fails++ #[test]+ #[should_panic]+ fn verify_mutal_corrections_cause_failure() {+ assert_suggestion_result(+ "gooder",+ TestLinter::new(&[(&["gooder"], &["more good"])]),+ "better",+ );+ }+/// Asserts that the lint's message matches the expected message.#[track_caller]pub fn assert_lint_message(text: &str, mut linter: impl Linter, expected_message: &str) {- let test = Document::new_markdown_default_curated(text);+ let test = Document::new_plain_english_curated(text);let lints = linter.lint(&test);- // Just check the first lint for now+ // Just check the first lint for now - TODOif let Some(lint) = lints.first()&& lint.message != expected_message{@@ -571,42 +819,4 @@ pub mod tests {);}}-- fn transform_nth_str(text: &str, linter: &mut impl Linter, n: usize) -> String {- let mut text_chars: Vec<char> = text.chars().collect();-- let mut iter_count = 0;-- loop {- let test = Document::new_from_vec(- text_chars.clone().into(),- &Markdown::default(),- &FstDictionary::curated(),- );- let lints = linter.lint(&test);-- if let Some(lint) = lints.first() {- if let Some(sug) = lint.suggestions.get(n) {- sug.apply(lint.span, &mut text_chars);-- // let transformed_str: String = text_chars.iter().collect();- // dbg!(transformed_str);- } else {- break;- }- } else {- break;- }-- iter_count += 1;-- if iter_count == 100 {- break;- }- }-- eprintln!("Corrected {iter_count} times.");-- text_chars.iter().collect()- }}diff --git a/harper-core/src/linting/modal_seem.rs b/harper-core/src/linting/modal_seem.rsindex d4aed8103..e1a98653a 100644--- a/harper-core/src/linting/modal_seem.rs+++ b/harper-core/src/linting/modal_seem.rs@@ -102,9 +102,7 @@ impl ExprLinter for ModalSeem {#[cfg(test)]mod tests {use super::ModalSeem;- use crate::linting::tests::{- assert_lint_count, assert_no_lints, assert_nth_suggestion_result, assert_suggestion_result,- };+ use crate::linting::tests::{assert_lint_count, assert_no_lints, assert_suggestion_result};#[test]fn corrects_basic_case() {@@ -126,11 +124,10 @@ mod tests {#[test]fn offers_be_option() {- assert_nth_suggestion_result(+ assert_suggestion_result("It may seen impossible to finish.",ModalSeem::default(),"It may be impossible to finish.",- 1,);}diff --git a/harper-core/src/linting/most_number.rs b/harper-core/src/linting/most_number.rsindex 4c9894ee8..36ac302d1 100644--- a/harper-core/src/linting/most_number.rs+++ b/harper-core/src/linting/most_number.rs@@ -77,9 +77,7 @@ impl ExprLinter for MostNumber {#[cfg(test)]mod tests {- use crate::linting::tests::{- assert_lint_count, assert_suggestion_result, assert_top3_suggestion_result,- };+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};use super::MostNumber;@@ -95,7 +93,7 @@ mod tests {#[test]#[ignore = "replace_with_match_case currently produces 'GreatEst'"]fn corrects_most_amount_title_case() {- assert_top3_suggestion_result(+ assert_suggestion_result("Area of Container with the Most Amount of Water",MostNumber::default(),"Area of Container with the Greatest Amount of Water",@@ -104,7 +102,7 @@ mod tests {#[test]fn corrects_most_amount() {- assert_top3_suggestion_result(+ assert_suggestion_result("I just wanted to make sure it's good for the most amount of people, not just what I like.",MostNumber::default(),"I just wanted to make sure it's good for the greatest amount of people, not just what I like.",@@ -122,7 +120,7 @@ mod tests {#[test]fn corrects_most_amount_with_maximum() {- assert_top3_suggestion_result(+ assert_suggestion_result("If you want to support the most amount of different architectures ...",MostNumber::default(),"If you want to support the maximum amount of different architectures ...",diff --git a/harper-core/src/linting/obsess_preposition.rs b/harper-core/src/linting/obsess_preposition.rsindex a1766ebcf..4c5867a5e 100644--- a/harper-core/src/linting/obsess_preposition.rs+++ b/harper-core/src/linting/obsess_preposition.rs@@ -102,9 +102,7 @@ impl ExprLinter for ObsessPreposition {#[cfg(test)]mod tests {use super::ObsessPreposition;- use crate::linting::tests::{- assert_lint_message, assert_suggestion_result, assert_top3_suggestion_result,- };+ use crate::linting::tests::{assert_lint_message, assert_suggestion_result};#[test]fn fix_obsess_on() {@@ -153,7 +151,7 @@ mod tests {#[test]fn fix_obsessed_on() {- assert_top3_suggestion_result(+ assert_suggestion_result("Secondly, if you get obsessed on any idea, then delve in it and don't worry about anything others until you get there.",ObsessPreposition::default(),"Secondly, if you get obsessed with any idea, then delve in it and don't worry about anything others until you get there.",diff --git a/harper-core/src/linting/one_of_the_singular.rs b/harper-core/src/linting/one_of_the_singular.rsindex 59102b625..57a954eba 100644--- a/harper-core/src/linting/one_of_the_singular.rs+++ b/harper-core/src/linting/one_of_the_singular.rs@@ -149,12 +149,12 @@ impl<D: Dictionary + 'static> ExprLinter for OneOfTheSingular<D> {#[cfg(test)]mod tests {use super::OneOfTheSingular;- use crate::linting::tests::{assert_no_lints, assert_top3_suggestion_result};+ use crate::linting::tests::{assert_no_lints, assert_suggestion_result};use crate::spell::FstDictionary;#[test]fn fix_one_of_the_noun() {- assert_top3_suggestion_result(+ assert_suggestion_result("one of the noun",OneOfTheSingular::new(FstDictionary::curated()),"one of the nouns",@@ -163,7 +163,7 @@ mod tests {#[test]fn fix_one_of_the_noun_noun() {- assert_top3_suggestion_result(+ assert_suggestion_result("one of the car park",OneOfTheSingular::new(FstDictionary::curated()),"one of the car parks",@@ -172,7 +172,7 @@ mod tests {#[test]fn fix_one_of_the_adj_noun() {- assert_top3_suggestion_result(+ assert_suggestion_result("one of the best noun",OneOfTheSingular::new(FstDictionary::curated()),"one of the best nouns",@@ -181,7 +181,7 @@ mod tests {#[test]fn fix_one_of_the_adv_adv_adj_adj_noun_noun() {- assert_top3_suggestion_result(+ assert_suggestion_result("one of the really incredibly big red rubber ball",OneOfTheSingular::new(FstDictionary::curated()),"one of the really incredibly big red rubber balls",@@ -190,7 +190,7 @@ mod tests {#[test]fn fix_one_of_the_best_tutorial() {- assert_top3_suggestion_result(+ assert_suggestion_result("Bro casually dropped one of the best graphics tutorial I've ever seen and thought we wouldn't notice",OneOfTheSingular::new(FstDictionary::curated()),"Bro casually dropped one of the best graphics tutorials I've ever seen and thought we wouldn't notice",@@ -199,7 +199,7 @@ mod tests {#[test]fn fix_one_of_the_neat_trick() {- assert_top3_suggestion_result(+ assert_suggestion_result("One of the neat trick with AVX-512 is that given a mask",OneOfTheSingular::new(FstDictionary::curated()),"One of the neat tricks with AVX-512 is that given a mask",@@ -208,7 +208,7 @@ mod tests {#[test]fn fix_one_of_the_latest_version() {- assert_top3_suggestion_result(+ assert_suggestion_result("Footer line shown since one of the latest version",OneOfTheSingular::new(FstDictionary::curated()),"Footer line shown since one of the latest versions",@@ -217,7 +217,7 @@ mod tests {#[test]fn fix_one_of_the_node() {- assert_top3_suggestion_result(+ assert_suggestion_result("... noticed occasional production issue when one of the node loses connection",OneOfTheSingular::new(FstDictionary::curated()),"... noticed occasional production issue when one of the nodes loses connection",@@ -226,7 +226,7 @@ mod tests {#[test]fn fix_one_of_the_unstaged_file() {- assert_top3_suggestion_result(+ assert_suggestion_result("Sublime Merge hangs if one of the unstaged file is a pretty ...",OneOfTheSingular::new(FstDictionary::curated()),"Sublime Merge hangs if one of the unstaged files is a pretty ...",@@ -235,7 +235,7 @@ mod tests {#[test]fn fix_one_of_the_tedious_things() {- assert_top3_suggestion_result(+ assert_suggestion_result("One of the tedious thing in Stack Overflow is to grab example data provided by users",OneOfTheSingular::new(FstDictionary::curated()),"One of the tedious things in Stack Overflow is to grab example data provided by users",@@ -244,7 +244,7 @@ mod tests {#[test]fn fix_one_of_the_brave_process() {- assert_top3_suggestion_result(+ assert_suggestion_result("One of the Brave Process is consuming almost 170%",OneOfTheSingular::new(FstDictionary::curated()),"One of the Brave Processes is consuming almost 170%",@@ -253,7 +253,7 @@ mod tests {#[test]fn fix_one_of_the_most_cumbersome_thing() {- assert_top3_suggestion_result(+ assert_suggestion_result("One of the most cumbersome thing to create in markdown is a table.",OneOfTheSingular::new(FstDictionary::curated()),"One of the most cumbersome things to create in markdown is a table.",@@ -262,7 +262,7 @@ mod tests {#[test]fn fix_one_of_the_test() {- assert_top3_suggestion_result(+ assert_suggestion_result("Not passing one of the test",OneOfTheSingular::new(FstDictionary::curated()),"Not passing one of the tests",@@ -271,7 +271,7 @@ mod tests {#[test]fn fix_one_of_the_process_main_thread() {- assert_top3_suggestion_result(+ assert_suggestion_result("And those threads life cycle is very long, sometimes, it will be one of the process main thread",OneOfTheSingular::new(FstDictionary::curated()),"And those threads life cycle is very long, sometimes, it will be one of the process main threads",diff --git a/harper-core/src/linting/phrase_set_corrections/tests.rs b/harper-core/src/linting/phrase_set_corrections/tests.rsindex c7c47c03a..9734ddfd0 100644--- a/harper-core/src/linting/phrase_set_corrections/tests.rs+++ b/harper-core/src/linting/phrase_set_corrections/tests.rs@@ -1,6 +1,5 @@use crate::linting::tests::{- assert_good_and_bad_suggestions, assert_lint_count, assert_no_lints,- assert_nth_suggestion_result, assert_suggestion_result, assert_top3_suggestion_result,+ assert_good_and_bad_suggestions, assert_lint_count, assert_no_lints, assert_suggestion_result,};use super::lint_group;@@ -1932,7 +1931,7 @@ fn correct_double_edged_space_plural() {#[test]fn corrects_allocs() {- assert_top3_suggestion_result(+ assert_suggestion_result("cmd/compile: avoid allocs by better tracking of literals for interface conversions and make",lint_group(),"cmd/compile: avoid allocations by better tracking of literals for interface conversions and make",@@ -1941,7 +1940,7 @@ fn corrects_allocs() {#[test]fn expand_alloc() {- assert_top3_suggestion_result(+ assert_suggestion_result("Used to find system libraries that alloc RWX regions on load.",lint_group(),"Used to find system libraries that allocate RWX regions on load.",@@ -2160,11 +2159,10 @@ fn correct_how_it_looks_like_1() {#[test]fn correct_how_it_looks_like_2() {- assert_nth_suggestion_result(+ assert_suggestion_result("This is how it looks like when run from Windows PowerShell or Cmd: image.",lint_group(),"This is what it looks like when run from Windows PowerShell or Cmd: image.",- 1,);}@@ -2179,11 +2177,10 @@ fn correct_how_they_look_like_1() {#[test]fn correct_how_they_look_like_2() {- assert_nth_suggestion_result(+ assert_suggestion_result("So for now I'll just leave this issue here of how they look like in the XLSX",lint_group(),"So for now I'll just leave this issue here of what they look like in the XLSX",- 1,);}@@ -2198,11 +2195,10 @@ fn correct_how_they_looks_like_1() {#[test]fn correct_how_they_looks_like_2() {- assert_nth_suggestion_result(+ assert_suggestion_result("You can check how they looks like on Android app by this command:",lint_group(),"You can check what they look like on Android app by this command:",- 1,);}@@ -2217,11 +2213,10 @@ fn correct_how_she_looks_like_1() {#[test]fn correct_how_he_looks_like_2() {- assert_nth_suggestion_result(+ assert_suggestion_result("Here's how he looks like, when he's supposed to just look like his old fatui design.",lint_group(),"Here's what he looks like, when he's supposed to just look like his old fatui design.",- 1,);}@@ -2236,11 +2231,10 @@ fn correct_how_it_look_like_1() {#[test]fn correct_how_it_look_like_2() {- assert_nth_suggestion_result(+ assert_suggestion_result("Here is how it look like in your browser:",lint_group(),"Here is what it looks like in your browser:",- 1,);}@@ -2769,7 +2763,7 @@ fn correct_atomic_a_whole_entire_to_a_whole() {#[test]fn correct_atomic_a_whole_entire_to_an_entire() {- assert_nth_suggestion_result("a whole entire", lint_group(), "an entire", 1);+ assert_suggestion_result("a whole entire", lint_group(), "an entire");}#[test]@@ -2783,11 +2777,10 @@ fn correct_real_world_a_whole_entire_to_a_whole() {#[test]fn correct_real_world_a_whole_entire_to_an_entire() {- assert_nth_suggestion_result(+ assert_suggestion_result("I am not sure I can pass in a whole entire query via the include.",lint_group(),"I am not sure I can pass in an entire query via the include.",- 1,);}diff --git a/harper-core/src/linting/possessive_your.rs b/harper-core/src/linting/possessive_your.rsindex 713dc2aba..68d69943a 100644--- a/harper-core/src/linting/possessive_your.rs+++ b/harper-core/src/linting/possessive_your.rs@@ -66,9 +66,7 @@ impl ExprLinter for PossessiveYour {#[cfg(test)]mod tests {- use crate::linting::tests::{- assert_lint_count, assert_no_lints, assert_suggestion_result, assert_top3_suggestion_result,- };+ use crate::linting::tests::{assert_lint_count, assert_no_lints, assert_suggestion_result};use super::PossessiveYour;@@ -101,8 +99,8 @@ mod tests {}#[test]- fn test_top3_suggestion_your() {- assert_top3_suggestion_result(+ fn test_suggestion_your() {+ assert_suggestion_result("You combination of artist and teacher.",PossessiveYour::default(),"Your combination of artist and teacher.",@@ -110,8 +108,8 @@ mod tests {}#[test]- fn test_top3_suggestion_youre_a() {- assert_top3_suggestion_result(+ fn test_suggestion_youre_a() {+ assert_suggestion_result("You combination of artist and teacher.",PossessiveYour::default(),"You're a combination of artist and teacher.",@@ -120,8 +118,8 @@ mod tests {#[test]#[ignore]- fn test_top3_suggestion_multiple() {- assert_top3_suggestion_result(+ fn test_suggestion_multiple() {+ assert_suggestion_result("You knowledge. You imagination. You icosahedron",PossessiveYour::default(),"Your knowledge. Your imagination. You're an icosahedron",diff --git a/harper-core/src/linting/pronoun_are.rs b/harper-core/src/linting/pronoun_are.rsindex 4324349f9..362af6f43 100644--- a/harper-core/src/linting/pronoun_are.rs+++ b/harper-core/src/linting/pronoun_are.rs@@ -91,9 +91,7 @@ impl ExprLinter for PronounAre {#[cfg(test)]mod tests {use super::PronounAre;- use crate::linting::tests::{- assert_lint_count, assert_nth_suggestion_result, assert_suggestion_result,- };+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};#[test]fn fixes_you_r() {@@ -106,11 +104,10 @@ mod tests {#[test]fn offers_contraction_option() {- assert_nth_suggestion_result(+ assert_suggestion_result("You r absolutely right.",PronounAre::default(),"You're absolutely right.",- 1,);}diff --git a/harper-core/src/linting/pronoun_verb_agreement.rs b/harper-core/src/linting/pronoun_verb_agreement.rsindex ada135a37..d3ef6cea0 100644--- a/harper-core/src/linting/pronoun_verb_agreement.rs+++ b/harper-core/src/linting/pronoun_verb_agreement.rs@@ -246,9 +246,7 @@ where#[cfg(test)]mod lints {use super::PronounVerbAgreement;- use crate::linting::tests::{- assert_no_lints, assert_suggestion_result, assert_top3_suggestion_result,- };+ use crate::linting::tests::{assert_no_lints, assert_suggestion_result};use crate::spell::FstDictionary;// Expected to be fixed, but there are exceptions@@ -291,7 +289,7 @@ mod lints {#[test]fn issue_233_2_reverse() {- assert_top3_suggestion_result(+ assert_suggestion_result("She sit under the AC.",PronounVerbAgreement::new(FstDictionary::curated()),"She sits under the AC.",diff --git a/harper-core/src/linting/redundant_additive_adverbs.rs b/harper-core/src/linting/redundant_additive_adverbs.rsindex 2137f038d..778affb76 100644--- a/harper-core/src/linting/redundant_additive_adverbs.rs+++ b/harper-core/src/linting/redundant_additive_adverbs.rs@@ -113,13 +113,13 @@ impl ExprLinter for RedundantAdditiveAdverbs {#[cfg(test)]mod tests {use super::RedundantAdditiveAdverbs;- use crate::linting::tests::{assert_lint_count, assert_top3_suggestion_result};+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};// Basic unit tests#[test]fn flag_as_well_too() {- assert_top3_suggestion_result(+ assert_suggestion_result("Yeah, we definitely miss him on this episode here, but you could probably get him on a podcast that's more focused on what Equinix is doing as well too, specifically.",RedundantAdditiveAdverbs::default(),"Yeah, we definitely miss him on this episode here, but you could probably get him on a podcast that's more focused on what Equinix is doing as well, specifically.",@@ -128,7 +128,7 @@ mod tests {#[test]fn flag_too_also() {- assert_top3_suggestion_result(+ assert_suggestion_result("The #1 uptime service with many servers and is easy to setup. It is free too also.",RedundantAdditiveAdverbs::default(),"The #1 uptime service with many servers and is easy to setup. It is free also.",@@ -164,7 +164,7 @@ mod tests {#[test]fn flag_too_as_well() {- assert_top3_suggestion_result(+ assert_suggestion_result("Module name itself was changed too as well.",RedundantAdditiveAdverbs::default(),"Module name itself was changed as well.",diff --git a/harper-core/src/linting/regionalisms.rs b/harper-core/src/linting/regionalisms.rsindex ca4573217..cdb3121bd 100644--- a/harper-core/src/linting/regionalisms.rs+++ b/harper-core/src/linting/regionalisms.rs@@ -696,13 +696,11 @@ impl ExprLinter for Regionalisms {#[cfg(test)]mod tests {use super::*;- use crate::linting::tests::{- assert_lint_count, assert_suggestion_result, assert_top3_suggestion_result,- };+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};#[test]fn uk_to_us_food() {- assert_top3_suggestion_result(+ assert_suggestion_result("I can't eat aubergine or coriander, so I'll just have a bag of crisps.",Regionalisms::new(Dialect::American),"I can't eat eggplant or cilantro, so I'll just have a bag of chips.",@@ -711,7 +709,7 @@ mod tests {#[test]fn au_to_us_phone() {- assert_top3_suggestion_result(+ assert_suggestion_result("I dropped my mobile phone in the esky and now it's covered in tomato sauce.",Regionalisms::new(Dialect::American),// Tomato sauce is valid in American English, it just means pasta sauce rather than ketchup.@@ -721,7 +719,7 @@ mod tests {#[test]fn au_to_uk_cars() {- assert_top3_suggestion_result(+ assert_suggestion_result("Drive the station wagon onto the footpath and hand me that spanner.",Regionalisms::new(Dialect::British),"Drive the estate onto the pavement and hand me that spanner.",@@ -730,7 +728,7 @@ mod tests {#[test]fn au_to_us_cars() {- assert_top3_suggestion_result(+ assert_suggestion_result("Drive the station wagon onto the footpath and hand me that spanner.",Regionalisms::new(Dialect::American),"Drive the station wagon onto the sidewalk and hand me that wrench.",@@ -739,7 +737,7 @@ mod tests {#[test]fn us_to_au_baby() {- assert_top3_suggestion_result(+ assert_suggestion_result("Wash the pacifier under the faucet.",Regionalisms::new(Dialect::Australian),"Wash the dummy under the tap.",@@ -748,7 +746,7 @@ mod tests {#[test]fn us_to_uk_fuel() {- assert_top3_suggestion_result(+ assert_suggestion_result("I needed more gasoline to drive the truck to the soccer match.",Regionalisms::new(Dialect::British),"I needed more petrol to drive the truck to the football match.",@@ -757,7 +755,7 @@ mod tests {#[test]fn au_to_uk_light() {- assert_top3_suggestion_result(+ assert_suggestion_result("Can you sell me a light globe for this torch?",Regionalisms::new(Dialect::British),"Can you sell me a light bulb for this torch?",@@ -766,7 +764,7 @@ mod tests {#[test]fn us_to_au_oops() {- assert_top3_suggestion_result(+ assert_suggestion_result("I spilled ketchup on my clean sweater.",Regionalisms::new(Dialect::Australian),"I spilled tomato sauce on my clean jumper.",@@ -784,7 +782,7 @@ mod tests {#[test]fn uk_to_us_windscreen() {- assert_top3_suggestion_result(+ assert_suggestion_result("Detect raindrops on vehicle windscreen by combining various region proposal algorithm with Convolutional Neural Network.",Regionalisms::new(Dialect::American),"Detect raindrops on vehicle windshield by combining various region proposal algorithm with Convolutional Neural Network.",@@ -793,7 +791,7 @@ mod tests {#[test]fn au_to_uk_blood_nose() {- assert_top3_suggestion_result(+ assert_suggestion_result("Oh no! I got a blood nose.",Regionalisms::new(Dialect::British),"Oh no! I got a nosebleed.",@@ -802,7 +800,7 @@ mod tests {#[test]fn in_to_non_in_updation() {- assert_top3_suggestion_result(+ assert_suggestion_result("Add apps to queue for updation or installation and resize it.",Regionalisms::new(Dialect::American),"Add apps to queue for update or installation and resize it.",diff --git a/harper-core/src/linting/regular_irregulars.rs b/harper-core/src/linting/regular_irregulars.rsnew file mode 100644index 000000000..57203502a--- /dev/null+++ b/harper-core/src/linting/regular_irregulars.rs@@ -0,0 +1,368 @@+use crate::{+ Token,+ char_string::CharStringExt,+ expr::Expr,+ irregular_nouns::IrregularNouns,+ irregular_verbs::IrregularVerbs,+ linting::{ExprLinter, Lint, LintKind, Suggestion, expr_linter::Chunk},+ spell::Dictionary,+};+use hashbrown::HashSet;++pub struct RegularIrregulars<D> {+ exp: Box<dyn Expr>,+ dict: D,+}++impl<D> RegularIrregulars<D>+where+ D: Dictionary,+{+ pub fn new(dict: D) -> Self {+ Self {+ exp: Box::new(|tok: &Token, src: &[char]| {+ tok.kind.is_oov()+ && tok+ .span+ .get_content(src)+ .ends_with_any_ignore_ascii_case_chars(&[+ &['s'],+ &['e', 'd'],+ &['e', 'r'],+ &['e', 's', 't'],+ ])+ }),+ dict,+ }+ }+}++impl<D> ExprLinter for RegularIrregulars<D>+where+ D: Dictionary,+{+ type Unit = Chunk;++ fn description(&self) -> &'static str {+ "Replaces wrong regular inflections of words with their correct irregular forms."+ }++ fn expr(&self) -> &dyn Expr {+ self.exp.as_ref()+ }++ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {+ if toks.len() != 1 {+ return None;+ }+ let tok = &toks[0];+ let span = tok.span;+ let chars = span.get_content(src);+ let word = span.get_content_string(src);++ let mut suggs: HashSet<String> = HashSet::new();++ handle_plural_nouns(&self.dict, &mut suggs, chars);+ handle_past_verbs(&self.dict, &mut suggs, chars);+ handle_adjectives(&mut suggs, chars);++ let suggestions: Vec<_> = suggs+ .iter()+ .map(|good_str| Suggestion::replace_with_match_case(good_str.chars().collect(), chars))+ .collect();++ if suggestions.is_empty() {+ return None;+ }+ let irregulars = suggs+ .iter()+ .map(|s| format!("'{}'", s))+ .collect::<Vec<_>>()+ .join(" or ");++ Some(Lint {+ span,+ lint_kind: LintKind::Grammar,+ message: format!(+ "Use the irregular form {} instead of '{}'",+ irregulars, word+ ),+ suggestions,+ ..Default::default()+ })+ }+}++fn get_irreg_compar(word: &str) -> Option<&'static [&'static str]> {+ match word {+ "good" => Some(&["better"]),+ "far" => Some(&["farther", "further"]),+ "well" => Some(&["better"]),+ "bad" => Some(&["worse"]),+ _ => None,+ }+}++fn get_irreg_super(word: &str) -> Option<&'static [&'static str]> {+ match word {+ "good" => Some(&["best"]),+ "far" => Some(&["farthest", "furthest"]),+ "well" => Some(&["best"]),+ "bad" => Some(&["worst"]),+ _ => None,+ }+}++fn handle_adjectives(suggs: &mut HashSet<String>, chars: &[char]) {+ if chars.ends_with_ignore_ascii_case_str("er") {+ // Irregular comparatives: gooder -> better etc.+ let key = chars[..chars.len() - 2].iter().collect::<String>();+ if let Some(forms) = get_irreg_compar(&key) {+ suggs.extend(forms.iter().map(|s| s.to_string()));+ }+ }++ if chars.ends_with_ignore_ascii_case_str("est") {+ // Irregular superlatives: goodest -> best etc.+ let key = chars[..chars.len() - 2].iter().collect::<String>();+ if let Some(forms) = get_irreg_super(&key) {+ suggs.extend(forms.iter().map(|s| s.to_string()));+ }+ }+}++fn handle_plural_nouns(dict: &dyn Dictionary, suggs: &mut HashSet<String>, chars: &[char]) {+ let mut plurals = vec![];+ let mut sg_candidates = vec![];++ if let Some(drop_s) = chars.strip_suffix(&['s']) {+ sg_candidates.push(drop_s);++ if let Some(drop_es) = drop_s.strip_suffix(&['e']) {+ sg_candidates.push(drop_es);+ }++ let singulars = sg_candidates.iter().filter(|sg| {+ dict.get_word_metadata(sg)+ .is_some_and(|m| m.is_singular_noun())+ });++ singulars.into_iter().for_each(|sg| {+ // irregular plurals+ if let Some(pl) =+ IrregularNouns::curated().get_plural_for_singular(&sg.iter().collect::<String>())+ {+ plurals.push(pl.chars().collect());+ }++ // skys -> sky -> skies etc.+ if let Some(drop_y) = sg.strip_suffix(&['y']) {+ let mut add_ies = drop_y.to_vec();+ add_ies.extend(['i', 'e', 's']);+ if dict+ .get_word_metadata(&add_ies)+ .is_some_and(|m| m.is_plural_noun())+ {+ plurals.push(add_ies);+ }+ }++ // knifes -> knife -> knives etc. (No because "knifes" is a legit verb)+ if let Some(drop_fe) = sg.strip_suffix(&['f', 'e']) {+ let mut add_ves = drop_fe.to_vec();+ add_ves.extend(['v', 'e', 's']);+ if dict+ .get_word_metadata(&add_ves)+ .is_some_and(|m| m.is_plural_noun())+ {+ plurals.push(add_ves);+ }+ }+ // calfs -> calf -> calves etc.+ if let Some(drop_f) = sg.strip_suffix(&['f']) {+ let mut add_ves = drop_f.to_vec();+ add_ves.extend(['v', 'e', 's']);+ if dict+ .get_word_metadata(&add_ves)+ .is_some_and(|m| m.is_plural_noun())+ {+ plurals.push(add_ves);+ }+ }+ // tomatos -> tomato -> tomatoes etc.+ // TODO: boxs -> box -> boxes ?+ if sg.ends_with_ignore_ascii_case_chars(&['o']) {+ let mut add_es = sg.to_vec();+ add_es.extend(['e', 's']);+ if dict+ .get_word_metadata(&add_es)+ .is_some_and(|m| m.is_plural_noun())+ {+ plurals.push(add_es);+ }+ }++ // TODO are there words which double the last consonant to pluralize? gas? whiz?+ });++ plurals.iter().for_each(|pl| {+ suggs.insert(pl.iter().collect());+ });+ }+}++fn handle_past_verbs(dict: &dyn Dictionary, suggs: &mut HashSet<String>, chars: &[char]) {+ let mut pasts: HashSet<Vec<char>> = HashSet::new();+ let mut vp_candidates = vec![];++ if chars.ends_with_ignore_ascii_case_chars(&['e', 'd']) {+ vp_candidates.push(&chars[..chars.len() - 2]); // drop_ed+ vp_candidates.push(&chars[..chars.len() - 1]); // drop_d++ // Handle doubled consonant before -ed (e.g., "resetted" -> "reset")+ // Check if position len-3 and len-4 are same char (the doubled consonant)+ if chars.len() >= 5 && chars[chars.len() - 3] == chars[chars.len() - 4] {+ vp_candidates.push(&chars[..chars.len() - 3]); // drop one of the doubled consonants + ed+ }+ }++ let lemmata = vp_candidates.into_iter().filter(|vp| {+ dict.get_word_metadata(vp)+ .is_some_and(|m| m.is_verb_lemma())+ });++ lemmata.into_iter().for_each(|lem| {+ let lem_str = lem.iter().collect::<String>();++ // Irregular verbs+ if let Some((pt, pp)) = IrregularVerbs::curated().get_pasts_for_lemma(&lem_str) {+ pasts.insert(pt.chars().collect());+ pasts.insert(pp.chars().collect());+ }+ });++ pasts.iter().for_each(|p| {+ suggs.insert(p.iter().collect());+ });+}++#[cfg(test)]+mod tests {+ mod nouns {+ use super::super::RegularIrregulars;+ use crate::linting::tests::assert_suggestion_result;+ use crate::spell::FstDictionary;++ #[test]+ fn fix_irregulars() {+ assert_suggestion_result(+ "Womans and childs first",+ RegularIrregulars::new(FstDictionary::curated()),+ "Women and children first",+ );+ }++ #[test]+ fn fix_ys_and_fs() {+ assert_suggestion_result(+ "Kittys playing on the shelfs.",+ RegularIrregulars::new(FstDictionary::curated()),+ "Kitties playing on the shelves.",+ );+ }++ #[test]+ fn fix_os_and_oes() {+ assert_suggestion_result(+ "The heros climb the volcanos",+ RegularIrregulars::new(FstDictionary::curated()),+ "The heroes climb the volcanoes",+ );+ }++ #[test]+ fn fix_oxen_and_meatloaves() {+ assert_suggestion_result(+ "These meatloafs are made out of oxes.",+ RegularIrregulars::new(FstDictionary::curated()),+ "These meatloaves are made out of oxen.",+ );+ }+ }++ mod verbs {+ use super::super::RegularIrregulars;+ use crate::linting::tests::assert_suggestion_result;+ use crate::spell::FstDictionary;++ #[test]+ fn fix_irregular_past_verb() {+ assert_suggestion_result(+ "I eated the banana.",+ RegularIrregulars::new(FstDictionary::curated()),+ "I ate the banana.",+ );+ }++ #[test]+ fn fix_readed() {+ assert_suggestion_result(+ "He readed the newspaper",+ RegularIrregulars::new(FstDictionary::curated()),+ "He read the newspaper",+ );+ }++ #[test]+ fn fix_writed() {+ assert_suggestion_result(+ "She writed many lines of code.",+ RegularIrregulars::new(FstDictionary::curated()),+ "She wrote many lines of code.",+ );+ }++ #[test]+ fn fix_runned() {+ assert_suggestion_result(+ "I runned faster than ever!",+ RegularIrregulars::new(FstDictionary::curated()),+ "I ran faster than ever!",+ );+ }++ #[test]+ fn fix_resetted() {+ assert_suggestion_result(+ "I resetted the phone to factory settings.",+ RegularIrregulars::new(FstDictionary::curated()),+ "I reset the phone to factory settings.",+ );+ }++ #[test]+ fn fix_eat_drink_sleep() {+ assert_suggestion_result(+ "I eated and drinked too much but I sleeped good.",+ RegularIrregulars::new(FstDictionary::curated()),+ "I ate and drank too much but I slept good.",+ );+ }+ }++ mod adjectives {+ use super::super::RegularIrregulars;+ use crate::linting::tests::assert_good_and_bad_suggestions;+ use crate::spell::FstDictionary;++ #[test]+ fn fix_adjectives() {+ assert_good_and_bad_suggestions(+ "This way is farer.",+ RegularIrregulars::new(FstDictionary::curated()),+ &["This way is farther.", "This way is further."],+ &[],+ );+ }+ }+}diff --git a/harper-core/src/linting/simple_past_to_past_participle.rs b/harper-core/src/linting/simple_past_to_past_participle.rsindex a111e80d9..540cfba0c 100644--- a/harper-core/src/linting/simple_past_to_past_participle.rs+++ b/harper-core/src/linting/simple_past_to_past_participle.rs@@ -105,9 +105,7 @@ impl ExprLinter for SimplePastToPastParticiple {#[cfg(test)]mod tests {use super::SimplePastToPastParticiple;- use crate::linting::tests::{- assert_no_lints, assert_suggestion_result, assert_top3_suggestion_result,- };+ use crate::linting::tests::{assert_no_lints, assert_suggestion_result};// "Be" and "have"@@ -122,7 +120,7 @@ mod tests {#[test]fn correct_had_went() {- assert_top3_suggestion_result(+ assert_suggestion_result("Not sure if TroLoos had went from Tasmota->minimal->Tasmota, or directly Minimal->Tasmota, but going ESPHome->Minimal->Tasmota is not possible",SimplePastToPastParticiple::default(),"Not sure if TroLoos had gone from Tasmota->minimal->Tasmota, or directly Minimal->Tasmota, but going ESPHome->Minimal->Tasmota is not possible",@@ -203,7 +201,7 @@ mod tests {#[test]fn correct_had_began() {- assert_top3_suggestion_result(+ assert_suggestion_result("I had began learning Android App development since Aug 2021",SimplePastToPastParticiple::default(),"I had begun learning Android App development since Aug 2021",@@ -221,7 +219,7 @@ mod tests {#[test]fn correct_have_saw() {- assert_top3_suggestion_result(+ assert_suggestion_result("I have saw that your paper has been accepted by JAIR",SimplePastToPastParticiple::default(),"I have seen that your paper has been accepted by JAIR",diff --git a/harper-core/src/linting/since_duration.rs b/harper-core/src/linting/since_duration.rsindex b9000a286..ea7434fe5 100644--- a/harper-core/src/linting/since_duration.rs+++ b/harper-core/src/linting/since_duration.rs@@ -90,9 +90,7 @@ impl ExprLinter for SinceDuration {#[cfg(test)]mod tests {use super::SinceDuration;- use crate::linting::tests::{- assert_lint_count, assert_no_lints, assert_top3_suggestion_result,- };+ use crate::linting::tests::{assert_lint_count, assert_no_lints, assert_suggestion_result};#[test]fn catches_spelled() {@@ -130,7 +128,7 @@ mod tests {#[test]fn correct_without_issues() {- assert_top3_suggestion_result(+ assert_suggestion_result("I'm running v2.2.1 on bare metal (no docker, vm) since two weeks without issues.",SinceDuration::default(),"I'm running v2.2.1 on bare metal (no docker, vm) for two weeks without issues.",@@ -139,7 +137,7 @@ mod tests {#[test]fn correct_anything_back() {- assert_top3_suggestion_result(+ assert_suggestion_result("I have not heard anything back since three months.",SinceDuration::default(),"I have not heard anything back for three months.",@@ -148,7 +146,7 @@ mod tests {#[test]fn correct_get_done() {- assert_top3_suggestion_result(+ assert_suggestion_result("I am trying to get this done since two days, someone please help.",SinceDuration::default(),"I am trying to get this done for two days, someone please help.",@@ -157,7 +155,7 @@ mod tests {#[test]fn correct_deprecated() {- assert_top3_suggestion_result(+ assert_suggestion_result("This project is now officially deprecated, since I worked with virtualabs on the next version of Mirage since three years now: an ecosystem of tools named WHAD.",SinceDuration::default(),"This project is now officially deprecated, since I worked with virtualabs on the next version of Mirage for three years now: an ecosystem of tools named WHAD.",@@ -166,7 +164,7 @@ mod tests {#[test]fn correct_same() {- assert_top3_suggestion_result(+ assert_suggestion_result("Same! Since two days.",SinceDuration::default(),"Same! For two days.",@@ -175,7 +173,7 @@ mod tests {#[test]fn correct_what_changed() {- assert_top3_suggestion_result(+ assert_suggestion_result("What changed since two weeks?",SinceDuration::default(),"What changed since two weeks ago?",@@ -184,7 +182,7 @@ mod tests {#[test]fn correct_with_period() {- assert_top3_suggestion_result(+ assert_suggestion_result("I have been waiting since two hours.",SinceDuration::default(),"I have been waiting since two hours ago.",@@ -193,7 +191,7 @@ mod tests {#[test]fn correct_with_exclamation() {- assert_top3_suggestion_result(+ assert_suggestion_result("I have been waiting since two hours!",SinceDuration::default(),"I have been waiting since two hours ago!",@@ -202,7 +200,7 @@ mod tests {#[test]fn correct_with_question_mark() {- assert_top3_suggestion_result(+ assert_suggestion_result("Have you been waiting since two hours?",SinceDuration::default(),"Have you been waiting for two hours?",@@ -211,7 +209,7 @@ mod tests {#[test]fn correct_with_comma() {- assert_top3_suggestion_result(+ assert_suggestion_result("Since two days, I have been trying to get this done.",SinceDuration::default(),"For two days, I have been trying to get this done.",@@ -220,7 +218,7 @@ mod tests {#[test]fn correct_for_title_case() {- assert_top3_suggestion_result(+ assert_suggestion_result("Since 45 Minutes I See The Following Picture In The Terminal.",SinceDuration::default(),"For 45 Minutes I See The Following Picture In The Terminal.",@@ -229,7 +227,7 @@ mod tests {#[test]fn correct_for_all_caps() {- assert_top3_suggestion_result(+ assert_suggestion_result("STOPPED SINCE 12 HOURS WITH EXIT CODE 0",SinceDuration::default(),"STOPPED FOR 12 HOURS WITH EXIT CODE 0",@@ -238,7 +236,7 @@ mod tests {#[test]fn correct_ago_title_case() {- assert_top3_suggestion_result(+ assert_suggestion_result("It Is In Development Since Two Years.",SinceDuration::default(),"It Is In Development Since Two Years Ago.",@@ -247,7 +245,7 @@ mod tests {#[test]fn correct_ago_all_caps() {- assert_top3_suggestion_result(+ assert_suggestion_result("BUG: SINCE 6 MONTHS UNLOAD CHECKPOINT",SinceDuration::default(),"BUG: SINCE 6 MONTHS AGO UNLOAD CHECKPOINT",@@ -257,7 +255,7 @@ mod tests {#[test]#[ignore = "We can't yet handle modifiers like 'over'. Plus it doesn't work with 'ago'."]fn not_yet_handled() {- assert_top3_suggestion_result(+ assert_suggestion_result("It's an asked feature since over 9 years",SinceDuration::default(),"It's an asked feature for over 9 years.",@@ -267,7 +265,7 @@ mod tests {#[test]#[ignore = "We can't yet handle modifiers like 'more than'. Plus it doesn't work with 'ago'."]fn not_yet_handled_2() {- assert_top3_suggestion_result(+ assert_suggestion_result("It's an asked feature since more than 9 years",SinceDuration::default(),"It's an asked feature for more than 9 years.",@@ -277,7 +275,7 @@ mod tests {#[test]#[ignore = "We can't yet handle indefinite numbers."]fn not_yet_handled_3() {- assert_top3_suggestion_result(+ assert_suggestion_result("I use a Wacom Cintiq 27QHDT since several years on Linux",SinceDuration::default(),"I use a Wacom Cintiq 27QHDT for several years on Linux",diff --git a/harper-core/src/linting/some_without_article.rs b/harper-core/src/linting/some_without_article.rsindex 94ee43a4e..22d177054 100644--- a/harper-core/src/linting/some_without_article.rs+++ b/harper-core/src/linting/some_without_article.rs@@ -54,9 +54,7 @@ impl ExprLinter for SomeWithoutArticle {#[cfg(test)]mod tests {- use crate::linting::tests::{- assert_lint_count, assert_nth_suggestion_result, assert_suggestion_result,- };+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};use super::SomeWithoutArticle;@@ -89,11 +87,10 @@ mod tests {#[test]fn second_suggestion_produces_the_same() {- assert_nth_suggestion_result(+ assert_suggestion_result("We kept the some approach from last year.",SomeWithoutArticle::default(),"We kept the same approach from last year.",- 1,);}diff --git a/harper-core/src/linting/something_is.rs b/harper-core/src/linting/something_is.rsindex 39513415a..e3c13935e 100644--- a/harper-core/src/linting/something_is.rs+++ b/harper-core/src/linting/something_is.rs@@ -63,9 +63,7 @@ impl ExprLinter for SomethingIs {#[cfg(test)]mod tests {use super::SomethingIs;- use crate::linting::tests::{- assert_lint_count, assert_no_lints, assert_nth_suggestion_result, assert_suggestion_result,- };+ use crate::linting::tests::{assert_lint_count, assert_no_lints, assert_suggestion_result};#[test]fn fixes_somethings_going() {@@ -123,11 +121,10 @@ mod tests {#[test]fn offers_is_expansion() {- assert_nth_suggestion_result(+ assert_suggestion_result("Somethings going wrong.",SomethingIs::default(),"Something is going wrong.",- 1,);}diff --git a/harper-core/src/linting/spell_check.rs b/harper-core/src/linting/spell_check.rsindex 7752ad694..715cc9a9b 100644--- a/harper-core/src/linting/spell_check.rs+++ b/harper-core/src/linting/spell_check.rs@@ -146,9 +146,7 @@ mod tests {use crate::spell::{Dictionary, FstDictionary, MergedDictionary, MutableDictionary};use crate::{Dialect,- linting::tests::{- assert_lint_count, assert_suggestion_result, assert_top3_suggestion_result,- },+ linting::tests::{assert_lint_count, assert_suggestion_result},};use crate::{DictWordMetadata, Document};@@ -323,7 +321,7 @@ mod tests {#[test]fn corrects_abandonedware_1131_1166() {// assert_suggestion_result(- assert_top3_suggestion_result(+ assert_suggestion_result("Abandonedware is abandoned. Do not bother submitting issues about the empty page bug. Author moved to greener pastures",SpellCheck::new(FstDictionary::curated(), Dialect::American),"Abandonware is abandoned. Do not bother submitting issues about the empty page bug. Author moved to greener pastures",@@ -476,13 +474,13 @@ mod tests {#[test]fn issue_2026() {- assert_top3_suggestion_result(+ assert_suggestion_result("'Tere' is supposed to be 'There'",SpellCheck::new(FstDictionary::curated(), Dialect::British),"'There' is supposed to be 'There'",);- assert_top3_suggestion_result(+ assert_suggestion_result("'fll' is supposed to be 'fill'",SpellCheck::new(FstDictionary::curated(), Dialect::British),"'fill' is supposed to be 'fill'",@@ -490,7 +488,7 @@ mod tests {}#[test]fn issue_2261() {- assert_top3_suggestion_result(+ assert_suggestion_result("Generaly",SpellCheck::new(FstDictionary::curated(), Dialect::British),"Generally",@@ -956,7 +954,7 @@ mod tests {// is_ei_ie_misspelling#[test]fn fix_cheif_and_recieved() {- assert_top3_suggestion_result(+ assert_suggestion_result("The cheif recieved a letter.",SpellCheck::new(FstDictionary::curated(), Dialect::British),"The chief received a letter.",@@ -966,7 +964,7 @@ mod tests {#[test]#[ignore = "known failure due to bug"]fn fix_cheif_and_recieved_titlecase() {- assert_top3_suggestion_result(+ assert_suggestion_result("The Cheif Recieved a Letter.",SpellCheck::new(FstDictionary::curated(), Dialect::British),"The Chief Received a Letter.",@@ -976,7 +974,7 @@ mod tests {#[test]#[ignore = "known failure due to bug"]fn fix_cheif_and_recieved_all_caps() {- assert_top3_suggestion_result(+ assert_suggestion_result("THE CHEIF RECIEVED A LETTER.",SpellCheck::new(FstDictionary::curated(), Dialect::British),"THE CHEIF RECEIVED A LETTER.",@@ -985,7 +983,7 @@ mod tests {#[test]fn fix_vs_apostrophe() {- assert_top3_suggestion_result(+ assert_suggestion_result("v's",SpellCheck::new(FstDictionary::curated(), Dialect::British),"vs",@@ -994,7 +992,7 @@ mod tests {#[test]fn fix_vs_typographical_apostrophe() {- assert_top3_suggestion_result(+ assert_suggestion_result("v’s",SpellCheck::new(FstDictionary::curated(), Dialect::British),"vs",@@ -1003,7 +1001,7 @@ mod tests {#[test]fn fix_childrens_missing_apostrophe() {- assert_top3_suggestion_result(+ assert_suggestion_result("childrens",SpellCheck::new(FstDictionary::curated(), Dialect::British),"children's",diff --git a/harper-core/src/linting/split_words.rs b/harper-core/src/linting/split_words.rsindex a7945151e..c045cde51 100644--- a/harper-core/src/linting/split_words.rs+++ b/harper-core/src/linting/split_words.rs@@ -147,7 +147,6 @@ impl ExprLinter for SplitWords {mod tests {use crate::linting::tests::{assert_good_and_bad_suggestions, assert_no_lints, assert_suggestion_result,- assert_top3_suggestion_result,};use super::SplitWords;@@ -228,7 +227,7 @@ mod tests {#[test]fn test_atall_to_a_tall() {- assert_top3_suggestion_result("atall", SplitWords::default(), "a tall");+ assert_suggestion_result("atall", SplitWords::default(), "a tall");}#[test]diff --git a/harper-core/src/linting/take_medicine.rs b/harper-core/src/linting/take_medicine.rsindex 4766f7f48..b1552f2ac 100644--- a/harper-core/src/linting/take_medicine.rs+++ b/harper-core/src/linting/take_medicine.rs@@ -114,9 +114,7 @@ impl ExprLinter for TakeMedicine {#[cfg(test)]mod tests {use super::TakeMedicine;- use crate::linting::tests::{- assert_lint_count, assert_nth_suggestion_result, assert_suggestion_result,- };+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};#[test]fn swaps_ate_antibiotics() {@@ -210,11 +208,10 @@ mod tests {#[test]fn offers_swallow_alternative() {- assert_nth_suggestion_result(+ assert_suggestion_result("He ate the medication without water.",TakeMedicine::default(),"He swallowed the medication without water.",- 1,);}diff --git a/harper-core/src/linting/the_my.rs b/harper-core/src/linting/the_my.rsindex f3a926c4f..1e58466cf 100644--- a/harper-core/src/linting/the_my.rs+++ b/harper-core/src/linting/the_my.rs@@ -85,9 +85,7 @@ impl ExprLinter for TheMy {#[cfg(test)]mod tests {use super::TheMy;- use crate::linting::tests::{- assert_lint_count, assert_nth_suggestion_result, assert_suggestion_result,- };+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};#[test]fn correct_the_my_atomic_lowercase() {@@ -96,7 +94,7 @@ mod tests {#[test]fn correct_the_my_atomic_2nd_suggestion() {- assert_nth_suggestion_result("the my", TheMy::default(), "the", 1);+ assert_suggestion_result("the my", TheMy::default(), "the");}#[test]@@ -111,7 +109,7 @@ mod tests {#[test]fn correct_my_the_atomic_2nd_suggestion() {- assert_nth_suggestion_result("my the", TheMy::default(), "the", 1);+ assert_suggestion_result("my the", TheMy::default(), "the");}#[test]diff --git a/harper-core/src/linting/throw_away.rs b/harper-core/src/linting/throw_away.rsindex 496fcb2fa..d0dd3d545 100644--- a/harper-core/src/linting/throw_away.rs+++ b/harper-core/src/linting/throw_away.rs@@ -52,9 +52,7 @@ impl ExprLinter for ThrowAway {#[cfg(test)]mod tests {use super::ThrowAway;- use crate::linting::tests::{- assert_lint_count, assert_no_lints, assert_nth_suggestion_result, assert_suggestion_result,- };+ use crate::linting::tests::{assert_lint_count, assert_no_lints, assert_suggestion_result};#[test]fn corrects_simple_case() {@@ -67,11 +65,10 @@ mod tests {#[test]fn offers_past_tense_option() {- assert_nth_suggestion_result(+ assert_suggestion_result("We through away the old code.",ThrowAway::default(),"We threw away the old code.",- 1,);}diff --git a/harper-core/src/linting/throw_rubbish.rs b/harper-core/src/linting/throw_rubbish.rsindex 13e4486e3..a6a28eaef 100644--- a/harper-core/src/linting/throw_rubbish.rs+++ b/harper-core/src/linting/throw_rubbish.rs@@ -127,7 +127,7 @@ fn is_progressive_verb_form(document: &Document, token: &crate::Token) -> bool {#[cfg(test)]mod tests {use super::ThrowRubbish;- use crate::linting::tests::{assert_lint_count, assert_top3_suggestion_result};+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};// Test correct patterns (should not trigger lint)#[test]@@ -164,7 +164,7 @@ mod tests {// Test suggestions#[test]fn correct_thrown_some_trash() {- assert_top3_suggestion_result(+ assert_suggestion_result("I've thrown some trash",ThrowRubbish,"I've thrown some trash away",@@ -173,7 +173,7 @@ mod tests {#[test]fn correct_throws_garbage() {- assert_top3_suggestion_result(+ assert_suggestion_result("That guy just throws his garbage",ThrowRubbish,"That guy just throws out his garbage",@@ -189,7 +189,7 @@ mod tests {// Sentences from GitHub#[test]fn correct_come_close_to_throw_trash() {- assert_top3_suggestion_result(+ assert_suggestion_result("Smart Dustbin is a trash bin that automatically opens when you come close to throw trash.",ThrowRubbish,"Smart Dustbin is a trash bin that automatically opens when you come close to throw away trash.",@@ -198,7 +198,7 @@ mod tests {#[test]fn correct_thrown_rubbish() {- assert_top3_suggestion_result(+ assert_suggestion_result("Add a script that draws the bin behind thrown rubbish.",ThrowRubbish,"Add a script that draws the bin behind thrown away rubbish.",@@ -208,7 +208,7 @@ mod tests {#[test]#[ignore = "`on` doesn't go with `throw` but with `daily basis`"]fn correct_encourage_people_to_throw_trash() {- assert_top3_suggestion_result(+ assert_suggestion_result("The app main goal is to encourage people to throw trash they can found on a daily basis.",ThrowRubbish,"The app main goal is to encourage people to throw away trash they can found on a daily basis.",@@ -217,7 +217,7 @@ mod tests {#[test]fn correct_a_person_throwing_trash() {- assert_top3_suggestion_result(+ assert_suggestion_result("I think personally the icons look okay, aside from the clear prompt one, as it's currently accented on a person throwing trash.",ThrowRubbish,"I think personally the icons look okay, aside from the clear prompt one, as it's currently accented on a person throwing away trash.",@@ -235,7 +235,7 @@ mod tests {#[test]fn correct_responsibly_throw_trash() {- assert_top3_suggestion_result(+ assert_suggestion_result("Reward system for people responsibly throwing trash saving the environment.",ThrowRubbish,"Reward system for people responsibly throwing away trash saving the environment.",@@ -268,7 +268,7 @@ mod tests {#[test]fn correct_threw_trash_properly() {- assert_top3_suggestion_result(+ assert_suggestion_result("we want to know which student threw trash properly so that we can reward that student",ThrowRubbish,"we want to know which student threw away trash properly so that we can reward that student",@@ -313,7 +313,7 @@ mod tests {#[test]fn correct_throwing_rubbish() {- assert_top3_suggestion_result(+ assert_suggestion_result("Admiring paintings, throwing rubbish, greeting.",ThrowRubbish,"Admiring paintings, throwing away rubbish, greeting.",diff --git a/harper-core/src/linting/to_adverb.rs b/harper-core/src/linting/to_adverb.rsindex fd5bf1b13..c1636dc39 100644--- a/harper-core/src/linting/to_adverb.rs+++ b/harper-core/src/linting/to_adverb.rs@@ -73,8 +73,7 @@ impl ExprLinter for ToAdverb {mod tests {use super::ToAdverb;use crate::linting::tests::{- assert_lint_count, assert_nth_suggestion_result, assert_suggestion_count,- assert_suggestion_result,+ assert_lint_count, assert_suggestion_count, assert_suggestion_result,};#[test]@@ -88,11 +87,10 @@ mod tests {#[test]fn alternative_moves_adverb() {- assert_nth_suggestion_result(+ assert_suggestion_result("Tom has decided to never to do that again.",ToAdverb::default(),"Tom has decided never to do that again.",- 1,);}diff --git a/harper-core/src/linting/use_title_case.rs b/harper-core/src/linting/use_title_case.rsindex d09db2400..8af954fc3 100644--- a/harper-core/src/linting/use_title_case.rs+++ b/harper-core/src/linting/use_title_case.rs@@ -44,14 +44,14 @@ impl<D: Dictionary + 'static> Linter for UseTitleCase<D> {#[cfg(test)]mod tests {- use crate::linting::tests::{assert_no_lints, assert_suggestion_result};+ use crate::linting::tests::{assert_markdown_suggestion_result, assert_no_lints};use crate::spell::FstDictionary;use super::UseTitleCase;#[test]fn simple_correction() {- assert_suggestion_result(+ assert_markdown_suggestion_result("# This is a title",UseTitleCase::new(FstDictionary::curated()),"# This Is a Title",@@ -60,7 +60,7 @@ mod tests {#[test]fn double_correction() {- assert_suggestion_result(+ assert_markdown_suggestion_result("# This is a title\n\n## This is a subtitle",UseTitleCase::new(FstDictionary::curated()),"# This Is a Title\n\n## This Is a Subtitle",@@ -77,7 +77,7 @@ mod tests {#[test]fn shoud_uppercase_possessive_determiners() {- assert_suggestion_result(+ assert_markdown_suggestion_result("# my/our/your/his/her/its/their",UseTitleCase::new(FstDictionary::curated()),"# My/Our/Your/His/Her/Its/Their",@@ -94,7 +94,7 @@ mod tests {#[test]fn still_fixes_non_first_small_words_after_leading_number() {- assert_suggestion_result(+ assert_markdown_suggestion_result("### 1. To do a thing",UseTitleCase::new(FstDictionary::curated()),"### 1. To Do a Thing",diff --git a/harper-core/src/linting/very_unique.rs b/harper-core/src/linting/very_unique.rsindex c83362e1e..adc2b2672 100644--- a/harper-core/src/linting/very_unique.rs+++ b/harper-core/src/linting/very_unique.rs@@ -67,7 +67,7 @@ impl ExprLinter for VeryUnique {#[cfg(test)]mod tests {use super::VeryUnique;- use crate::linting::tests::{assert_good_and_bad_suggestions, assert_top3_suggestion_result};+ use crate::linting::tests::{assert_good_and_bad_suggestions, assert_suggestion_result};#[test]fn fix_very_unique() {@@ -83,7 +83,7 @@ mod tests {#[test]fn fix_pretty_unique() {- assert_top3_suggestion_result(+ assert_suggestion_result("Numerous accounts with my exact full name/surname (which is pretty unique) has been created (most recently).",VeryUnique::default(),"Numerous accounts with my exact full name/surname (which is pretty rare) has been created (most recently).",@@ -104,7 +104,7 @@ mod tests {#[test]fn fix_somewhat_unique() {- assert_top3_suggestion_result(+ assert_suggestion_result("A new pack of somewhat unique upgrades for R.E.P.O.!",VeryUnique::default(),"A new pack of somewhat unusual upgrades for R.E.P.O.!",@@ -125,7 +125,7 @@ mod tests {#[test]fn fix_rather_unique() {- assert_top3_suggestion_result(+ assert_suggestion_result("I regret using the Vue compiler because the resulting AST is rather unique.",VeryUnique::default(),"I regret using the Vue compiler because the resulting AST is rather unusual.",diff --git a/harper-core/src/linting/vicious_loop/mod.rs b/harper-core/src/linting/vicious_loop/mod.rsindex 85e7c3da1..fa7e09320 100644--- a/harper-core/src/linting/vicious_loop/mod.rs+++ b/harper-core/src/linting/vicious_loop/mod.rs@@ -199,9 +199,7 @@ impl_expr_linter!(#[cfg(test)]mod tests {use super::{ViciousCircle, ViciousCircleOrCycle, ViciousCycle};- use crate::linting::tests::{- assert_no_lints, assert_suggestion_result, assert_top3_suggestion_result,- };+ use crate::linting::tests::{assert_no_lints, assert_suggestion_result};// Prefer "circle" - Made up, simple examples@@ -243,7 +241,7 @@ mod tests {#[test]fn fix_singular_and_plural_nouns() {- assert_top3_suggestion_result(+ assert_suggestion_result("The file Vicious Cycle Dataset.ods contains 33 vicious cycles from 13 open source systems studied in our paper.",ViciousCircle::default(),"The file Vicious Circle Dataset.ods contains 33 vicious circles from 13 open source systems studied in our paper.",diff --git a/harper-core/src/linting/win_prize.rs b/harper-core/src/linting/win_prize.rsindex ef8bd39e4..07558ab31 100644--- a/harper-core/src/linting/win_prize.rs+++ b/harper-core/src/linting/win_prize.rs@@ -60,9 +60,7 @@ impl ExprLinter for WinPrize {#[cfg(test)]mod tests {use super::WinPrize;- use crate::linting::tests::{- assert_lint_count, assert_suggestion_result, assert_top3_suggestion_result,- };+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};#[test]fn fix_price_singular() {@@ -75,7 +73,7 @@ mod tests {#[test]fn fix_price_plural() {- assert_top3_suggestion_result(+ assert_suggestion_result("Our team won the prices announced yesterday.",WinPrize::default(),"Our team won the prizes announced yesterday.",