diff options
author | Aleksey Kladov <[email protected]> | 2020-02-07 11:07:38 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-07 11:14:33 +0000 |
commit | aa1234e02b1166c57dd2a3cd27fd0b0b3c6cba7e (patch) | |
tree | f3f9d08b204ddef33054c06e7eff26dfcf1bb0b3 /crates/ra_assists/src/assists/apply_demorgan.rs | |
parent | 5aba5a756a19a54d5c4edd51d8055db36182688b (diff) |
Generalize invert_if to just always work
Diffstat (limited to 'crates/ra_assists/src/assists/apply_demorgan.rs')
-rw-r--r-- | crates/ra_assists/src/assists/apply_demorgan.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/crates/ra_assists/src/assists/apply_demorgan.rs b/crates/ra_assists/src/assists/apply_demorgan.rs index dac6280ad..ba08a8223 100644 --- a/crates/ra_assists/src/assists/apply_demorgan.rs +++ b/crates/ra_assists/src/assists/apply_demorgan.rs | |||
@@ -31,12 +31,14 @@ pub(crate) fn apply_demorgan(ctx: AssistCtx) -> Option<Assist> { | |||
31 | if !cursor_in_range { | 31 | if !cursor_in_range { |
32 | return None; | 32 | return None; |
33 | } | 33 | } |
34 | |||
34 | let lhs = expr.lhs()?; | 35 | let lhs = expr.lhs()?; |
35 | let lhs_range = lhs.syntax().text_range(); | 36 | let lhs_range = lhs.syntax().text_range(); |
37 | let not_lhs = invert_boolean_expression(lhs); | ||
38 | |||
36 | let rhs = expr.rhs()?; | 39 | let rhs = expr.rhs()?; |
37 | let rhs_range = rhs.syntax().text_range(); | 40 | let rhs_range = rhs.syntax().text_range(); |
38 | let not_lhs = invert_boolean_expression(&lhs)?; | 41 | let not_rhs = invert_boolean_expression(rhs); |
39 | let not_rhs = invert_boolean_expression(&rhs)?; | ||
40 | 42 | ||
41 | ctx.add_assist(AssistId("apply_demorgan"), "Apply De Morgan's law", |edit| { | 43 | ctx.add_assist(AssistId("apply_demorgan"), "Apply De Morgan's law", |edit| { |
42 | edit.target(op_range); | 44 | edit.target(op_range); |
@@ -77,12 +79,12 @@ mod tests { | |||
77 | } | 79 | } |
78 | 80 | ||
79 | #[test] | 81 | #[test] |
80 | fn demorgan_doesnt_apply_with_cursor_not_on_op() { | 82 | fn demorgan_general_case() { |
81 | check_assist_not_applicable(apply_demorgan, "fn f() { <|> !x || !x }") | 83 | check_assist(apply_demorgan, "fn f() { x ||<|> x }", "fn f() { !(!x &&<|> !x) }") |
82 | } | 84 | } |
83 | 85 | ||
84 | #[test] | 86 | #[test] |
85 | fn demorgan_doesnt_apply_when_operands_arent_negated_already() { | 87 | fn demorgan_doesnt_apply_with_cursor_not_on_op() { |
86 | check_assist_not_applicable(apply_demorgan, "fn f() { x ||<|> x }") | 88 | check_assist_not_applicable(apply_demorgan, "fn f() { <|> !x || !x }") |
87 | } | 89 | } |
88 | } | 90 | } |