From fd1585a071718ef9c9fb44f88336608dd7e624a5 Mon Sep 17 00:00:00 2001 From: gfreezy Date: Mon, 25 Mar 2019 01:05:11 +0800 Subject: inline immutable local varialbe --- crates/ra_assists/src/inline_local_variable.rs | 298 +++++++++++++++++++++++++ crates/ra_assists/src/lib.rs | 2 + 2 files changed, 300 insertions(+) create mode 100644 crates/ra_assists/src/inline_local_variable.rs (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/inline_local_variable.rs b/crates/ra_assists/src/inline_local_variable.rs new file mode 100644 index 000000000..ce0aafb27 --- /dev/null +++ b/crates/ra_assists/src/inline_local_variable.rs @@ -0,0 +1,298 @@ +use hir::db::HirDatabase; +use hir::source_binder::function_from_child_node; +use ra_syntax::{ast::{self, AstNode}, TextRange}; +use ra_syntax::ast::{PatKind, ExprKind}; + +use crate::{Assist, AssistCtx, AssistId}; +use crate::assist_ctx::AssistBuilder; + +pub(crate) fn inline_local_varialbe(mut ctx: AssistCtx) -> Option { + let let_stmt = ctx.node_at_offset::()?; + let bind_pat = match let_stmt.pat()?.kind() { + PatKind::BindPat(pat) => pat, + _ => return None, + }; + if bind_pat.is_mutable() { + return None; + } + let initializer = let_stmt.initializer()?; + let wrap_in_parens = match initializer.kind() { + ExprKind::LambdaExpr(_) => true, + ExprKind::IfExpr(_) => true, + ExprKind::LoopExpr(_) => true, + ExprKind::ForExpr(_) => true, + ExprKind::WhileExpr(_) => true, + ExprKind::ContinueExpr(_) => true, + ExprKind::BreakExpr(_) => true, + ExprKind::Label(_) => true, + ExprKind::ReturnExpr(_) => true, + ExprKind::MatchExpr(_) => true, + ExprKind::StructLit(_) => true, + ExprKind::CastExpr(_) => true, + ExprKind::PrefixExpr(_) => true, + ExprKind::RangeExpr(_) => true, + ExprKind::BinExpr(_) => true, + ExprKind::CallExpr(_) => false, + ExprKind::IndexExpr(_) => false, + ExprKind::MethodCallExpr(_) => false, + ExprKind::FieldExpr(_) => false, + ExprKind::TryExpr(_) => false, + ExprKind::RefExpr(_) => false, + ExprKind::Literal(_) => false, + ExprKind::TupleExpr(_) => false, + ExprKind::ArrayExpr(_) => false, + ExprKind::ParenExpr(_) => false, + ExprKind::PathExpr(_) => false, + ExprKind::BlockExpr(_) => false, + }; + + let delete_range = if let Some(whitespace) = + let_stmt.syntax().next_sibling().and_then(ast::Whitespace::cast) + { + TextRange::from_to(let_stmt.syntax().range().start(), whitespace.syntax().range().end()) + } else { + let_stmt.syntax().range() + }; + + let init_str = if wrap_in_parens { + format!("({})", initializer.syntax().text().to_string()) + } else { + initializer.syntax().text().to_string() + }; + let function = function_from_child_node(ctx.db, ctx.frange.file_id, bind_pat.syntax())?; + let scope = function.scopes(ctx.db); + let refs = scope.find_all_refs(bind_pat); + + ctx.add_action( + AssistId("inline_local_variable"), + "inline local variable", + move |edit: &mut AssistBuilder| { + edit.delete(delete_range); + for desc in refs { + edit.replace(desc.range, init_str.clone()) + } + edit.set_cursor(delete_range.start()) + }, + ); + + ctx.build() +} + +#[cfg(test)] +mod tests { + use crate::helpers::{check_assist, check_assist_not_applicable}; + + use super::*; + + #[test] + fn test_inline_let_bind_literal_expr() { + check_assist( + inline_local_varialbe, + " +fn bar(a: usize) {} +fn foo() { + let a<|> = 1; + a + 1; + if a > 10 { + } + + while a > 10 { + + } + let b = a * 10; + bar(a); +}", + " +fn bar(a: usize) {} +fn foo() { + <|>1 + 1; + if 1 > 10 { + } + + while 1 > 10 { + + } + let b = 1 * 10; + bar(1); +}", + ); + } + + #[test] + fn test_inline_let_bind_bin_expr() { + check_assist( + inline_local_varialbe, + " +fn bar(a: usize) {} +fn foo() { + let a<|> = 1 + 1; + a + 1; + if a > 10 { + } + + while a > 10 { + + } + let b = a * 10; + bar(a); +}", + " +fn bar(a: usize) {} +fn foo() { + <|>(1 + 1) + 1; + if (1 + 1) > 10 { + } + + while (1 + 1) > 10 { + + } + let b = (1 + 1) * 10; + bar((1 + 1)); +}", + ); + } + + #[test] + fn test_inline_let_bind_function_call_expr() { + check_assist( + inline_local_varialbe, + " +fn bar(a: usize) {} +fn foo() { + let a<|> = bar(1); + a + 1; + if a > 10 { + } + + while a > 10 { + + } + let b = a * 10; + bar(a); +}", + " +fn bar(a: usize) {} +fn foo() { + <|>bar(1) + 1; + if bar(1) > 10 { + } + + while bar(1) > 10 { + + } + let b = bar(1) * 10; + bar(bar(1)); +}", + ); + } + + #[test] + fn test_inline_let_bind_cast_expr() { + check_assist( + inline_local_varialbe, + " +fn bar(a: usize): usize { a } +fn foo() { + let a<|> = bar(1) as u64; + a + 1; + if a > 10 { + } + + while a > 10 { + + } + let b = a * 10; + bar(a); +}", + " +fn bar(a: usize): usize { a } +fn foo() { + <|>(bar(1) as u64) + 1; + if (bar(1) as u64) > 10 { + } + + while (bar(1) as u64) > 10 { + + } + let b = (bar(1) as u64) * 10; + bar((bar(1) as u64)); +}", + ); + } + + #[test] + fn test_inline_let_bind_block_expr() { + check_assist( + inline_local_varialbe, + " +fn foo() { + let a<|> = { 10 + 1 }; + a + 1; + if a > 10 { + } + + while a > 10 { + + } + let b = a * 10; + bar(a); +}", + " +fn foo() { + <|>{ 10 + 1 } + 1; + if { 10 + 1 } > 10 { + } + + while { 10 + 1 } > 10 { + + } + let b = { 10 + 1 } * 10; + bar({ 10 + 1 }); +}", + ); + } + + #[test] + fn test_inline_let_bind_paren_expr() { + check_assist( + inline_local_varialbe, + " +fn foo() { + let a<|> = ( 10 + 1 ); + a + 1; + if a > 10 { + } + + while a > 10 { + + } + let b = a * 10; + bar(a); +}", + " +fn foo() { + <|>( 10 + 1 ) + 1; + if ( 10 + 1 ) > 10 { + } + + while ( 10 + 1 ) > 10 { + + } + let b = ( 10 + 1 ) * 10; + bar(( 10 + 1 )); +}", + ); + } + + #[test] + fn test_not_inline_mut_variable() { + check_assist_not_applicable( + inline_local_varialbe, + " +fn foo() { + let mut a<|> = 1 + 1; + a + 1; +}", + ); + } +} diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index fc36e8cc9..378470ac8 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -92,6 +92,7 @@ mod change_visibility; mod fill_match_arms; mod fill_struct_fields; mod introduce_variable; +mod inline_local_variable; mod replace_if_let_with_match; mod split_import; mod remove_dbg; @@ -113,6 +114,7 @@ fn all_assists() -> &'static [fn(AssistCtx) -> Option Date: Mon, 25 Mar 2019 20:57:43 +0800 Subject: use | instead of multiple match arms --- crates/ra_assists/src/inline_local_variable.rs | 54 +++++++++++++------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/inline_local_variable.rs b/crates/ra_assists/src/inline_local_variable.rs index ce0aafb27..bd3cdb970 100644 --- a/crates/ra_assists/src/inline_local_variable.rs +++ b/crates/ra_assists/src/inline_local_variable.rs @@ -17,33 +17,33 @@ pub(crate) fn inline_local_varialbe(mut ctx: AssistCtx) -> Opt } let initializer = let_stmt.initializer()?; let wrap_in_parens = match initializer.kind() { - ExprKind::LambdaExpr(_) => true, - ExprKind::IfExpr(_) => true, - ExprKind::LoopExpr(_) => true, - ExprKind::ForExpr(_) => true, - ExprKind::WhileExpr(_) => true, - ExprKind::ContinueExpr(_) => true, - ExprKind::BreakExpr(_) => true, - ExprKind::Label(_) => true, - ExprKind::ReturnExpr(_) => true, - ExprKind::MatchExpr(_) => true, - ExprKind::StructLit(_) => true, - ExprKind::CastExpr(_) => true, - ExprKind::PrefixExpr(_) => true, - ExprKind::RangeExpr(_) => true, - ExprKind::BinExpr(_) => true, - ExprKind::CallExpr(_) => false, - ExprKind::IndexExpr(_) => false, - ExprKind::MethodCallExpr(_) => false, - ExprKind::FieldExpr(_) => false, - ExprKind::TryExpr(_) => false, - ExprKind::RefExpr(_) => false, - ExprKind::Literal(_) => false, - ExprKind::TupleExpr(_) => false, - ExprKind::ArrayExpr(_) => false, - ExprKind::ParenExpr(_) => false, - ExprKind::PathExpr(_) => false, - ExprKind::BlockExpr(_) => false, + ExprKind::LambdaExpr(_) + | ExprKind::IfExpr(_) + | ExprKind::LoopExpr(_) + | ExprKind::ForExpr(_) + | ExprKind::WhileExpr(_) + | ExprKind::ContinueExpr(_) + | ExprKind::BreakExpr(_) + | ExprKind::Label(_) + | ExprKind::ReturnExpr(_) + | ExprKind::MatchExpr(_) + | ExprKind::StructLit(_) + | ExprKind::CastExpr(_) + | ExprKind::PrefixExpr(_) + | ExprKind::RangeExpr(_) + | ExprKind::BinExpr(_) => true, + ExprKind::CallExpr(_) + | ExprKind::IndexExpr(_) + | ExprKind::MethodCallExpr(_) + | ExprKind::FieldExpr(_) + | ExprKind::TryExpr(_) + | ExprKind::RefExpr(_) + | ExprKind::Literal(_) + | ExprKind::TupleExpr(_) + | ExprKind::ArrayExpr(_) + | ExprKind::ParenExpr(_) + | ExprKind::PathExpr(_) + | ExprKind::BlockExpr(_) => false, }; let delete_range = if let Some(whitespace) = -- cgit v1.2.3 From 12b5d4f795f69f7fa07051cdec7a1347d3aa7924 Mon Sep 17 00:00:00 2001 From: Marco Groppo Date: Mon, 25 Mar 2019 23:53:57 +0100 Subject: Assist to flip (some) binary expressions. This assist can flip the following operators: ==, !=, >, >=, <, <=. --- crates/ra_assists/src/flip_binexpr.rs | 149 ++++++++++++++++++++++++++++++ crates/ra_assists/src/flip_eq_operands.rs | 86 ----------------- crates/ra_assists/src/lib.rs | 4 +- 3 files changed, 151 insertions(+), 88 deletions(-) create mode 100644 crates/ra_assists/src/flip_binexpr.rs delete mode 100644 crates/ra_assists/src/flip_eq_operands.rs (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/flip_binexpr.rs b/crates/ra_assists/src/flip_binexpr.rs new file mode 100644 index 000000000..8a0737b55 --- /dev/null +++ b/crates/ra_assists/src/flip_binexpr.rs @@ -0,0 +1,149 @@ +use hir::db::HirDatabase; +use ra_syntax::ast::{AstNode, BinExpr, BinOp}; + +use crate::{AssistCtx, Assist, AssistId}; + +/// Flip binary comparison expressions (==, !=, >, >=, <, <=). +pub(crate) fn flip_binexpr(mut ctx: AssistCtx) -> Option { + let expr = ctx.node_at_offset::()?; + let lhs = expr.lhs()?.syntax(); + let rhs = expr.rhs()?.syntax(); + let op_range = expr.op()?.range(); + // The assist should be available only if the cursor is on the operator + let cursor_in_range = ctx.frange.range.is_subrange(&op_range); + // The assist should be available only for these binary operators + // (it should not change the meaning of the expression) + let allowed_ops = [ + BinOp::EqualityTest, + BinOp::NegatedEqualityTest, + BinOp::GreaterTest, + BinOp::GreaterEqualTest, + BinOp::LesserTest, + BinOp::LesserEqualTest, + ]; + let op_kind = expr.op_kind()?; + if !cursor_in_range || !allowed_ops.iter().any(|o| *o == op_kind) { + return None; + } + let new_op = match op_kind { + BinOp::GreaterTest => Some("<"), + BinOp::GreaterEqualTest => Some("<="), + BinOp::LesserTest => Some(">"), + BinOp::LesserEqualTest => Some(">="), + _ => None, + }; + ctx.add_action(AssistId("flip_binexpr"), "flip binary expression", |edit| { + edit.target(op_range); + if let Some(new_op) = new_op { + edit.replace(op_range, new_op); + } + edit.replace(lhs.range(), rhs.text()); + edit.replace(rhs.range(), lhs.text()); + }); + + ctx.build() +} + +#[cfg(test)] +mod tests { + use super::*; + + use crate::helpers::{check_assist, check_assist_target}; + + #[test] + fn flip_eq_operands_for_simple_stmt() { + check_assist( + flip_binexpr, + "fn f() { let res = 1 ==<|> 2; }", + "fn f() { let res = 2 ==<|> 1; }", + ) + } + + #[test] + fn flip_neq_operands_for_simple_stmt() { + check_assist( + flip_binexpr, + "fn f() { let res = 1 !=<|> 2; }", + "fn f() { let res = 2 !=<|> 1; }", + ) + } + + #[test] + fn flip_gt_operands_for_simple_stmt() { + check_assist( + flip_binexpr, + "fn f() { let res = 1 ><|> 2; }", + "fn f() { let res = 2 <<|> 1; }", + ) + } + + #[test] + fn flip_gteq_operands_for_simple_stmt() { + check_assist( + flip_binexpr, + "fn f() { let res = 1 >=<|> 2; }", + "fn f() { let res = 2 <=<|> 1; }", + ) + } + + #[test] + fn flip_lt_operands_for_simple_stmt() { + check_assist( + flip_binexpr, + "fn f() { let res = 1 <<|> 2; }", + "fn f() { let res = 2 ><|> 1; }", + ) + } + + #[test] + fn flip_lteq_operands_for_simple_stmt() { + check_assist( + flip_binexpr, + "fn f() { let res = 1 <=<|> 2; }", + "fn f() { let res = 2 >=<|> 1; }", + ) + } + + #[test] + fn flip_eq_operands_for_complex_stmt() { + check_assist( + flip_binexpr, + "fn f() { let res = (1 + 1) ==<|> (2 + 2); }", + "fn f() { let res = (2 + 2) ==<|> (1 + 1); }", + ) + } + + #[test] + fn flip_eq_operands_in_match_expr() { + check_assist( + flip_binexpr, + r#" + fn dyn_eq(&self, other: &dyn Diagnostic) -> bool { + match other.downcast_ref::() { + None => false, + Some(it) => it ==<|> self, + } + } + "#, + r#" + fn dyn_eq(&self, other: &dyn Diagnostic) -> bool { + match other.downcast_ref::() { + None => false, + Some(it) => self ==<|> it, + } + } + "#, + ) + } + + #[test] + fn flip_eq_operands_target() { + check_assist_target(flip_binexpr, "fn f() { let res = 1 ==<|> 2; }", "==") + } + + #[test] + fn flip_gt_operands_target() { + check_assist_target(flip_binexpr, "fn f() { let res = 1 ><|> 2; }", ">") + } + +} diff --git a/crates/ra_assists/src/flip_eq_operands.rs b/crates/ra_assists/src/flip_eq_operands.rs deleted file mode 100644 index df0bb689d..000000000 --- a/crates/ra_assists/src/flip_eq_operands.rs +++ /dev/null @@ -1,86 +0,0 @@ -use hir::db::HirDatabase; -use ra_syntax::ast::{AstNode, BinExpr, BinOp}; - -use crate::{AssistCtx, Assist, AssistId}; - -pub(crate) fn flip_eq_operands(mut ctx: AssistCtx) -> Option { - let expr = ctx.node_at_offset::()?; - let lhs = expr.lhs()?.syntax(); - let rhs = expr.rhs()?.syntax(); - let op_range = expr.op()?.range(); - let cursor_in_range = ctx.frange.range.is_subrange(&op_range); - let allowed_ops = [BinOp::EqualityTest, BinOp::NegatedEqualityTest]; - let expr_op = expr.op_kind()?; - if !cursor_in_range || !allowed_ops.iter().any(|o| *o == expr_op) { - return None; - } - ctx.add_action(AssistId("flip_eq_operands"), "flip equality operands", |edit| { - edit.target(op_range); - edit.replace(lhs.range(), rhs.text()); - edit.replace(rhs.range(), lhs.text()); - }); - - ctx.build() -} - -#[cfg(test)] -mod tests { - use super::*; - - use crate::helpers::{check_assist, check_assist_target}; - - #[test] - fn flip_eq_operands_for_simple_stmt() { - check_assist( - flip_eq_operands, - "fn f() { let res = 1 ==<|> 2; }", - "fn f() { let res = 2 ==<|> 1; }", - ) - } - - #[test] - fn flip_neq_operands_for_simple_stmt() { - check_assist( - flip_eq_operands, - "fn f() { let res = 1 !=<|> 2; }", - "fn f() { let res = 2 !=<|> 1; }", - ) - } - - #[test] - fn flip_eq_operands_for_complex_stmt() { - check_assist( - flip_eq_operands, - "fn f() { let res = (1 + 1) ==<|> (2 + 2); }", - "fn f() { let res = (2 + 2) ==<|> (1 + 1); }", - ) - } - - #[test] - fn flip_eq_operands_in_match_expr() { - check_assist( - flip_eq_operands, - r#" - fn dyn_eq(&self, other: &dyn Diagnostic) -> bool { - match other.downcast_ref::() { - None => false, - Some(it) => it ==<|> self, - } - } - "#, - r#" - fn dyn_eq(&self, other: &dyn Diagnostic) -> bool { - match other.downcast_ref::() { - None => false, - Some(it) => self ==<|> it, - } - } - "#, - ) - } - - #[test] - fn flip_eq_operands_target() { - check_assist_target(flip_eq_operands, "fn f() { let res = 1 ==<|> 2; }", "==") - } -} diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 2e47b5215..c1514f8e5 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -88,7 +88,7 @@ where mod add_derive; mod add_impl; mod flip_comma; -mod flip_eq_operands; +mod flip_binexpr; mod change_visibility; mod fill_match_arms; mod fill_struct_fields; @@ -108,7 +108,7 @@ fn all_assists() -> &'static [fn(AssistCtx) -> Option Date: Tue, 26 Mar 2019 23:12:46 +0100 Subject: Flip any binary expression except assignments. --- crates/ra_assists/src/flip_binexpr.rs | 120 ++++++++++++++++------------------ 1 file changed, 56 insertions(+), 64 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/flip_binexpr.rs b/crates/ra_assists/src/flip_binexpr.rs index 8a0737b55..ec377642e 100644 --- a/crates/ra_assists/src/flip_binexpr.rs +++ b/crates/ra_assists/src/flip_binexpr.rs @@ -3,38 +3,26 @@ use ra_syntax::ast::{AstNode, BinExpr, BinOp}; use crate::{AssistCtx, Assist, AssistId}; -/// Flip binary comparison expressions (==, !=, >, >=, <, <=). +/// Flip binary expression assist. pub(crate) fn flip_binexpr(mut ctx: AssistCtx) -> Option { let expr = ctx.node_at_offset::()?; let lhs = expr.lhs()?.syntax(); let rhs = expr.rhs()?.syntax(); let op_range = expr.op()?.range(); - // The assist should be available only if the cursor is on the operator + // The assist should be applied only if the cursor is on the operator let cursor_in_range = ctx.frange.range.is_subrange(&op_range); - // The assist should be available only for these binary operators - // (it should not change the meaning of the expression) - let allowed_ops = [ - BinOp::EqualityTest, - BinOp::NegatedEqualityTest, - BinOp::GreaterTest, - BinOp::GreaterEqualTest, - BinOp::LesserTest, - BinOp::LesserEqualTest, - ]; - let op_kind = expr.op_kind()?; - if !cursor_in_range || !allowed_ops.iter().any(|o| *o == op_kind) { + if !cursor_in_range { return None; } - let new_op = match op_kind { - BinOp::GreaterTest => Some("<"), - BinOp::GreaterEqualTest => Some("<="), - BinOp::LesserTest => Some(">"), - BinOp::LesserEqualTest => Some(">="), - _ => None, - }; + let action: FlipAction = expr.op_kind()?.into(); + // The assist should not be applied for certain operators + if let FlipAction::DontFlip = action { + return None; + } + ctx.add_action(AssistId("flip_binexpr"), "flip binary expression", |edit| { edit.target(op_range); - if let Some(new_op) = new_op { + if let FlipAction::FlipAndReplaceOp(new_op) = action { edit.replace(op_range, new_op); } edit.replace(lhs.range(), rhs.text()); @@ -44,59 +32,74 @@ pub(crate) fn flip_binexpr(mut ctx: AssistCtx) -> Option for FlipAction { + fn from(op_kind: BinOp) -> Self { + match op_kind { + BinOp::Assignment => FlipAction::DontFlip, + BinOp::AddAssign => FlipAction::DontFlip, + BinOp::DivAssign => FlipAction::DontFlip, + BinOp::MulAssign => FlipAction::DontFlip, + BinOp::RemAssign => FlipAction::DontFlip, + BinOp::ShrAssign => FlipAction::DontFlip, + BinOp::ShlAssign => FlipAction::DontFlip, + BinOp::SubAssign => FlipAction::DontFlip, + BinOp::BitOrAssign => FlipAction::DontFlip, + BinOp::BitAndAssign => FlipAction::DontFlip, + BinOp::BitXorAssign => FlipAction::DontFlip, + BinOp::GreaterTest => FlipAction::FlipAndReplaceOp("<"), + BinOp::GreaterEqualTest => FlipAction::FlipAndReplaceOp("<="), + BinOp::LesserTest => FlipAction::FlipAndReplaceOp(">"), + BinOp::LesserEqualTest => FlipAction::FlipAndReplaceOp(">="), + _ => FlipAction::Flip, + } + } +} + #[cfg(test)] mod tests { use super::*; - use crate::helpers::{check_assist, check_assist_target}; + use crate::helpers::{ check_assist, check_assist_target, check_assist_not_applicable }; #[test] - fn flip_eq_operands_for_simple_stmt() { - check_assist( - flip_binexpr, - "fn f() { let res = 1 ==<|> 2; }", - "fn f() { let res = 2 ==<|> 1; }", - ) - } - - #[test] - fn flip_neq_operands_for_simple_stmt() { - check_assist( - flip_binexpr, - "fn f() { let res = 1 !=<|> 2; }", - "fn f() { let res = 2 !=<|> 1; }", - ) + fn flip_binexpr_target_is_the_op() { + check_assist_target(flip_binexpr, "fn f() { let res = 1 ==<|> 2; }", "==") } #[test] - fn flip_gt_operands_for_simple_stmt() { - check_assist( - flip_binexpr, - "fn f() { let res = 1 ><|> 2; }", - "fn f() { let res = 2 <<|> 1; }", - ) + fn flip_binexpr_not_applicable_for_assignment() { + check_assist_not_applicable(flip_binexpr, "fn f() { let mut _x = 1; _x +=<|> 2 }") } #[test] - fn flip_gteq_operands_for_simple_stmt() { + fn flip_binexpr_works_for_eq() { check_assist( flip_binexpr, - "fn f() { let res = 1 >=<|> 2; }", - "fn f() { let res = 2 <=<|> 1; }", + "fn f() { let res = 1 ==<|> 2; }", + "fn f() { let res = 2 ==<|> 1; }", ) } #[test] - fn flip_lt_operands_for_simple_stmt() { + fn flip_binexpr_works_for_gt() { check_assist( flip_binexpr, - "fn f() { let res = 1 <<|> 2; }", - "fn f() { let res = 2 ><|> 1; }", + "fn f() { let res = 1 ><|> 2; }", + "fn f() { let res = 2 <<|> 1; }", ) } #[test] - fn flip_lteq_operands_for_simple_stmt() { + fn flip_binexpr_works_for_lteq() { check_assist( flip_binexpr, "fn f() { let res = 1 <=<|> 2; }", @@ -105,7 +108,7 @@ mod tests { } #[test] - fn flip_eq_operands_for_complex_stmt() { + fn flip_binexpr_works_for_complex_expr() { check_assist( flip_binexpr, "fn f() { let res = (1 + 1) ==<|> (2 + 2); }", @@ -114,7 +117,7 @@ mod tests { } #[test] - fn flip_eq_operands_in_match_expr() { + fn flip_binexpr_works_inside_match() { check_assist( flip_binexpr, r#" @@ -135,15 +138,4 @@ mod tests { "#, ) } - - #[test] - fn flip_eq_operands_target() { - check_assist_target(flip_binexpr, "fn f() { let res = 1 ==<|> 2; }", "==") - } - - #[test] - fn flip_gt_operands_target() { - check_assist_target(flip_binexpr, "fn f() { let res = 1 ><|> 2; }", ">") - } - } -- cgit v1.2.3