From 5675e0cd409ab4d3ca0c1717e7ec41825d4a3315 Mon Sep 17 00:00:00 2001 From: Jeroen Vannevel Date: Mon, 10 Jan 2022 18:46:47 +0000 Subject: [PATCH] test cases with more branches --- .../src/handlers/merge_match_arms.rs | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/crates/ide_assists/src/handlers/merge_match_arms.rs b/crates/ide_assists/src/handlers/merge_match_arms.rs index b61edc8964b..8983aada34a 100644 --- a/crates/ide_assists/src/handlers/merge_match_arms.rs +++ b/crates/ide_assists/src/handlers/merge_match_arms.rs @@ -325,6 +325,64 @@ fn func() { Ok(x) | Err(x) => x.1.classify(), }; } +"#, + ); + } + + #[test] + fn merge_match_arms_same_type_subsequent_arm_with_different_type_in_other() { + check_assist( + merge_match_arms, + r#" +enum MyEnum { + OptionA(f32), + OptionB(f32), + OptionC(f64) +} + +fn func(e: MyEnum) { + match e { + MyEnum::OptionA(x) => $0x.classify(), + MyEnum::OptionB(x) => x.classify(), + MyEnum::OptionC(x) => x.classify(), + }; +} +"#, + r#" +enum MyEnum { + OptionA(f32), + OptionB(f32), + OptionC(f64) +} + +fn func(e: MyEnum) { + match e { + MyEnum::OptionA(x) | MyEnum::OptionB(x) => x.classify(), + MyEnum::OptionC(x) => x.classify(), + }; +} +"#, + ); + } + + #[test] + fn merge_match_arms_same_type_skip_arm_with_different_type_in_between() { + check_assist_not_applicable( + merge_match_arms, + r#" +enum MyEnum { + OptionA(f32), + OptionB(f64), + OptionC(f32) +} + +fn func(e: MyEnum) { + match e { + MyEnum::OptionA(x) => $0x.classify(), + MyEnum::OptionB(x) => x.classify(), + MyEnum::OptionC(x) => x.classify(), + }; +} "#, ); }