aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2020-11-12 16:47:58 +0000
committerLukas Wirth <[email protected]>2020-11-12 17:44:37 +0000
commitccdcd52975c16df217188ccb196f45041b6f0973 (patch)
tree3753bd44830b7e8540cec6eb2ffbc42fbd455db7 /crates/assists/src
parent9454a9e536d96c7e46378744b8d93cc039fa3b98 (diff)
Add extra test to extract_struct_from_enum_variant
Diffstat (limited to 'crates/assists/src')
-rw-r--r--crates/assists/src/handlers/extract_struct_from_enum_variant.rs29
1 files changed, 28 insertions, 1 deletions
diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs
index ef4dce477..067afabf2 100644
--- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -140,7 +140,7 @@ fn insert_import(
140 enum_module_def.clone(), 140 enum_module_def.clone(),
141 ctx.config.insert_use.prefix_kind, 141 ctx.config.insert_use.prefix_kind,
142 ); 142 );
143 if let Some(mut mod_path) = mod_path.filter(|path| !path.is_ident()) { 143 if let Some(mut mod_path) = mod_path {
144 mod_path.segments.pop(); 144 mod_path.segments.pop();
145 mod_path.segments.push(variant_hir_name.clone()); 145 mod_path.segments.push(variant_hir_name.clone());
146 let scope = ImportScope::find_insert_use_container(scope_node, ctx)?; 146 let scope = ImportScope::find_insert_use_container(scope_node, ctx)?;
@@ -449,6 +449,33 @@ fn f() {
449 ) 449 )
450 } 450 }
451 451
452 #[test]
453 fn test_extract_struct_record_nested_call_exp() {
454 check_assist(
455 extract_struct_from_enum_variant,
456 r#"
457enum A { <|>One { a: u32, b: u32 } }
458
459struct B(A);
460
461fn foo() {
462 let _ = B(A::One { a: 1, b: 2 });
463}
464"#,
465 r#"
466struct One{ pub a: u32, pub b: u32 }
467
468enum A { One(One) }
469
470struct B(A);
471
472fn foo() {
473 let _ = B(A::One(One { a: 1, b: 2 }));
474}
475"#,
476 );
477 }
478
452 fn check_not_applicable(ra_fixture: &str) { 479 fn check_not_applicable(ra_fixture: &str) {
453 let fixture = 480 let fixture =
454 format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE); 481 format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE);