From 251f9dfc8ae5475cc1276545d1e46e59f13a4b84 Mon Sep 17 00:00:00 2001 From: "nathan.whitaker" Date: Sun, 29 Aug 2021 13:14:03 -0400 Subject: [PATCH] Add tests for fill struct fields shorthand --- .../src/handlers/missing_fields.rs | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/crates/ide_diagnostics/src/handlers/missing_fields.rs b/crates/ide_diagnostics/src/handlers/missing_fields.rs index 616f49a3fa..d15da23c4a 100644 --- a/crates/ide_diagnostics/src/handlers/missing_fields.rs +++ b/crates/ide_diagnostics/src/handlers/missing_fields.rs @@ -342,6 +342,93 @@ fn f() { ); } + #[test] + fn test_fill_struct_fields_shorthand() { + check_fix( + r#" +struct S { a: &'static str, b: i32 } + +fn f() { + let a = "hello"; + let b = 1i32; + S { + $0 + }; +} +"#, + r#" +struct S { a: &'static str, b: i32 } + +fn f() { + let a = "hello"; + let b = 1i32; + S { + a, + b, + }; +} +"#, + ); + } + + #[test] + fn test_fill_struct_fields_shorthand_ty_mismatch() { + check_fix( + r#" +struct S { a: &'static str, b: i32 } + +fn f() { + let a = "hello"; + let b = 1usize; + S { + $0 + }; +} +"#, + r#" +struct S { a: &'static str, b: i32 } + +fn f() { + let a = "hello"; + let b = 1usize; + S { + a, + b: (), + }; +} +"#, + ); + } + + #[test] + fn test_fill_struct_fields_shorthand_unifies() { + check_fix( + r#" +struct S { a: &'static str, b: T } + +fn f() { + let a = "hello"; + let b = 1i32; + S { + $0 + }; +} +"#, + r#" +struct S { a: &'static str, b: T } + +fn f() { + let a = "hello"; + let b = 1i32; + S { + a, + b, + }; +} +"#, + ); + } + #[test] fn import_extern_crate_clash_with_inner_item() { // This is more of a resolver test, but doesn't really work with the hir_def testsuite.