From 21918c6f5e0add44c7ba0df362c4890494e86875 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 17 May 2021 12:37:22 +0300 Subject: minor: add missing tests --- .../ide/src/diagnostics/fixes/remove_semicolon.rs | 10 ++++++ .../src/diagnostics/fixes/replace_with_find_map.rs | 42 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) (limited to 'crates/ide') diff --git a/crates/ide/src/diagnostics/fixes/remove_semicolon.rs b/crates/ide/src/diagnostics/fixes/remove_semicolon.rs index 058002c69..45471da41 100644 --- a/crates/ide/src/diagnostics/fixes/remove_semicolon.rs +++ b/crates/ide/src/diagnostics/fixes/remove_semicolon.rs @@ -29,3 +29,13 @@ impl DiagnosticWithFix for RemoveThisSemicolon { Some(fix("remove_semicolon", "Remove this semicolon", source_change, semicolon)) } } + +#[cfg(test)] +mod tests { + use crate::diagnostics::tests::check_fix; + + #[test] + fn remove_semicolon() { + check_fix(r#"fn f() -> i32 { 92$0; }"#, r#"fn f() -> i32 { 92 }"#); + } +} diff --git a/crates/ide/src/diagnostics/fixes/replace_with_find_map.rs b/crates/ide/src/diagnostics/fixes/replace_with_find_map.rs index 5ddfd2064..b0ef7b44a 100644 --- a/crates/ide/src/diagnostics/fixes/replace_with_find_map.rs +++ b/crates/ide/src/diagnostics/fixes/replace_with_find_map.rs @@ -40,3 +40,45 @@ impl DiagnosticWithFix for ReplaceFilterMapNextWithFindMap { )) } } + +#[cfg(test)] +mod tests { + use crate::diagnostics::tests::check_fix; + + #[test] + fn replace_with_wind_map() { + check_fix( + r#" +//- /main.rs crate:main deps:core +use core::iter::Iterator; +use core::option::Option::{self, Some, None}; +fn foo() { + let m = [1, 2, 3].iter().$0filter_map(|x| if *x == 2 { Some (4) } else { None }).next(); +} +//- /core/lib.rs crate:core +pub mod option { + pub enum Option { Some(T), None } +} +pub mod iter { + pub trait Iterator { + type Item; + fn filter_map(self, f: F) -> FilterMap where F: FnMut(Self::Item) -> Option { FilterMap } + fn next(&mut self) -> Option; + } + pub struct FilterMap {} + impl Iterator for FilterMap { + type Item = i32; + fn next(&mut self) -> i32 { 7 } + } +} +"#, + r#" +use core::iter::Iterator; +use core::option::Option::{self, Some, None}; +fn foo() { + let m = [1, 2, 3].iter().find_map(|x| if *x == 2 { Some (4) } else { None }); +} +"#, + ) + } +} -- cgit v1.2.3