add tests

This commit is contained in:
soruh 2022-07-13 16:16:48 +02:00
parent 817082cad6
commit a5ad4de111
2 changed files with 177 additions and 0 deletions

View file

@ -345,6 +345,92 @@ fn test_fn() {
);
}
#[test]
fn test_fill_struct_zst_fields() {
check_fix(
r#"
struct Empty;
struct TestStruct { one: i32, two: Empty }
fn test_fn() {
let s = TestStruct {$0};
}
"#,
r#"
struct Empty;
struct TestStruct { one: i32, two: Empty }
fn test_fn() {
let s = TestStruct { one: 0, two: Empty };
}
"#,
);
check_fix(
r#"
enum Empty { Foo };
struct TestStruct { one: i32, two: Empty }
fn test_fn() {
let s = TestStruct {$0};
}
"#,
r#"
enum Empty { Foo };
struct TestStruct { one: i32, two: Empty }
fn test_fn() {
let s = TestStruct { one: 0, two: Empty::Foo };
}
"#,
);
// make sure the assist doesn't fill non Unit variants
check_fix(
r#"
struct Empty {};
struct TestStruct { one: i32, two: Empty }
fn test_fn() {
let s = TestStruct {$0};
}
"#,
r#"
struct Empty {};
struct TestStruct { one: i32, two: Empty }
fn test_fn() {
let s = TestStruct { one: 0, two: todo!() };
}
"#,
);
check_fix(
r#"
enum Empty { Foo {} };
struct TestStruct { one: i32, two: Empty }
fn test_fn() {
let s = TestStruct {$0};
}
"#,
r#"
enum Empty { Foo {} };
struct TestStruct { one: i32, two: Empty }
fn test_fn() {
let s = TestStruct { one: 0, two: todo!() };
}
"#,
);
}
#[test]
fn test_fill_struct_fields_self() {
check_fix(