Skip to content

Commit 251f9df

Browse files
committed
Add tests for fill struct fields shorthand
1 parent dcd4157 commit 251f9df

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

crates/ide_diagnostics/src/handlers/missing_fields.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,93 @@ fn f() {
342342
);
343343
}
344344

345+
#[test]
346+
fn test_fill_struct_fields_shorthand() {
347+
check_fix(
348+
r#"
349+
struct S { a: &'static str, b: i32 }
350+
351+
fn f() {
352+
let a = "hello";
353+
let b = 1i32;
354+
S {
355+
$0
356+
};
357+
}
358+
"#,
359+
r#"
360+
struct S { a: &'static str, b: i32 }
361+
362+
fn f() {
363+
let a = "hello";
364+
let b = 1i32;
365+
S {
366+
a,
367+
b,
368+
};
369+
}
370+
"#,
371+
);
372+
}
373+
374+
#[test]
375+
fn test_fill_struct_fields_shorthand_ty_mismatch() {
376+
check_fix(
377+
r#"
378+
struct S { a: &'static str, b: i32 }
379+
380+
fn f() {
381+
let a = "hello";
382+
let b = 1usize;
383+
S {
384+
$0
385+
};
386+
}
387+
"#,
388+
r#"
389+
struct S { a: &'static str, b: i32 }
390+
391+
fn f() {
392+
let a = "hello";
393+
let b = 1usize;
394+
S {
395+
a,
396+
b: (),
397+
};
398+
}
399+
"#,
400+
);
401+
}
402+
403+
#[test]
404+
fn test_fill_struct_fields_shorthand_unifies() {
405+
check_fix(
406+
r#"
407+
struct S<T> { a: &'static str, b: T }
408+
409+
fn f() {
410+
let a = "hello";
411+
let b = 1i32;
412+
S {
413+
$0
414+
};
415+
}
416+
"#,
417+
r#"
418+
struct S<T> { a: &'static str, b: T }
419+
420+
fn f() {
421+
let a = "hello";
422+
let b = 1i32;
423+
S {
424+
a,
425+
b,
426+
};
427+
}
428+
"#,
429+
);
430+
}
431+
345432
#[test]
346433
fn import_extern_crate_clash_with_inner_item() {
347434
// This is more of a resolver test, but doesn't really work with the hir_def testsuite.

0 commit comments

Comments
 (0)