Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(weir): test runner now tries all 'becomes' alternatives, not just first 3 (#3424)
Mister Lobstercd4547838730
diff --git a/harper-core/src/weir/mod.rs b/harper-core/src/weir/mod.rsindex 716c5b337..fc9939eab 100644--- a/harper-core/src/weir/mod.rs+++ b/harper-core/src/weir/mod.rs@@ -216,7 +216,7 @@ impl WeirLinter {Some(text_chars.iter().collect())}- fn transform_top3_to_expected(+ fn transform_to_expected(text: &str,expected: &str,linter: &mut impl Linter,@@ -244,7 +244,7 @@ impl WeirLinter {let lints = linter.lint(&doc);if let Some(lint) = lints.first() {- for i in 0..3 {+ for i in 0..lint.suggestions.len() {if let Some(next) = apply_nth_suggestion(¤t, lint, i)&& seen.insert(next.clone()){@@ -306,7 +306,7 @@ impl WeirLinter {.collect();for (text, expected) in tests {- let matched = transform_top3_to_expected(&text, &expected, self);+ let matched = transform_to_expected(&text, &expected, self);match matched {Some(result) => {@@ -641,6 +641,30 @@ pub mod tests {assert_eq!(res.err(), Some(Error::ExpectedVariableUndefined))}+ #[test]+ fn becomes_array_with_many_alternatives() {+ let source = r#"+ expr main (the fact)+ let message "Consider alternative phrasing"+ let description "Test that all 'becomes' alternatives can be reached"+ let kind "Miscellaneous"+ let becomes ["the allegation", "the idea", "the claim", "the story", "the rumor"]+ let strategy "Exact"++ test "There is truth to the fact that people like images." "There is truth to the allegation that people like images."+ test "There is truth to the fact that people like images." "There is truth to the idea that people like images."+ test "There is truth to the fact that people like images." "There is truth to the claim that people like images."+ test "There is truth to the fact that people like images." "There is truth to the story that people like images."+ test "There is truth to the fact that people like images." "There is truth to the rumor that people like images."++ allows "There is truth to the story that people like images."+ "#;++ let mut linter = WeirLinter::new(source).unwrap();+ assert_passes_all(&mut linter);+ assert_eq!(6, linter.count_tests());+ }+#[quickcheck]fn does_not_panic(s: String) {let _ = WeirLinter::new(s.as_str());