aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-17 22:36:25 +0100
committerAleksey Kladov <[email protected]>2021-06-17 22:36:25 +0100
commit89c2dff58a253416c2f005fe2478f4ca66bfdba6 (patch)
tree52ef7e0c0072aa9475856c031f1ca1a614b4347b
parentebb591a5704f767d783d57af7022272f665318ac (diff)
minor: simplify
-rw-r--r--crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs27
1 files changed, 12 insertions, 15 deletions
diff --git a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs
index d3ff7b65c..6c6ff16c2 100644
--- a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -48,6 +48,7 @@ pub(crate) fn extract_struct_from_enum_variant(
48 let variant_name = variant.name()?; 48 let variant_name = variant.name()?;
49 let variant_hir = ctx.sema.to_def(&variant)?; 49 let variant_hir = ctx.sema.to_def(&variant)?;
50 if existing_definition(ctx.db(), &variant_name, &variant_hir) { 50 if existing_definition(ctx.db(), &variant_name, &variant_hir) {
51 cov_mark::hit!(test_extract_enum_not_applicable_if_struct_exists);
51 return None; 52 return None;
52 } 53 }
53 54
@@ -300,18 +301,10 @@ fn reference_to_node(
300 301
301#[cfg(test)] 302#[cfg(test)]
302mod tests { 303mod tests {
303 use ide_db::helpers::FamousDefs;
304
305 use crate::tests::{check_assist, check_assist_not_applicable}; 304 use crate::tests::{check_assist, check_assist_not_applicable};
306 305
307 use super::*; 306 use super::*;
308 307
309 fn check_not_applicable(ra_fixture: &str) {
310 let fixture =
311 format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE);
312 check_assist_not_applicable(extract_struct_from_enum_variant, &fixture)
313 }
314
315 #[test] 308 #[test]
316 fn test_extract_struct_several_fields_tuple() { 309 fn test_extract_struct_several_fields_tuple() {
317 check_assist( 310 check_assist(
@@ -699,29 +692,33 @@ fn foo() {
699 692
700 #[test] 693 #[test]
701 fn test_extract_enum_not_applicable_for_element_with_no_fields() { 694 fn test_extract_enum_not_applicable_for_element_with_no_fields() {
702 check_not_applicable("enum A { $0One }"); 695 check_assist_not_applicable(extract_struct_from_enum_variant, r#"enum A { $0One }"#);
703 } 696 }
704 697
705 #[test] 698 #[test]
706 fn test_extract_enum_not_applicable_if_struct_exists() { 699 fn test_extract_enum_not_applicable_if_struct_exists() {
707 check_not_applicable( 700 cov_mark::check!(test_extract_enum_not_applicable_if_struct_exists);
708 r#"struct One; 701 check_assist_not_applicable(
709 enum A { $0One(u8, u32) }"#, 702 extract_struct_from_enum_variant,
703 r#"
704struct One;
705enum A { $0One(u8, u32) }
706"#,
710 ); 707 );
711 } 708 }
712 709
713 #[test] 710 #[test]
714 fn test_extract_not_applicable_one_field() { 711 fn test_extract_not_applicable_one_field() {
715 check_not_applicable(r"enum A { $0One(u32) }"); 712 check_assist_not_applicable(extract_struct_from_enum_variant, r"enum A { $0One(u32) }");
716 } 713 }
717 714
718 #[test] 715 #[test]
719 fn test_extract_not_applicable_no_field_tuple() { 716 fn test_extract_not_applicable_no_field_tuple() {
720 check_not_applicable(r"enum A { $0None() }"); 717 check_assist_not_applicable(extract_struct_from_enum_variant, r"enum A { $0None() }");
721 } 718 }
722 719
723 #[test] 720 #[test]
724 fn test_extract_not_applicable_no_field_named() { 721 fn test_extract_not_applicable_no_field_named() {
725 check_not_applicable(r"enum A { $0None {} }"); 722 check_assist_not_applicable(extract_struct_from_enum_variant, r"enum A { $0None {} }");
726 } 723 }
727} 724}