Skip to content

Commit

Permalink
add test for checking struct generated through macro
Browse files Browse the repository at this point in the history
  • Loading branch information
dfireBird committed Feb 26, 2024
1 parent 2ea7066 commit 8fa903a
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions crates/ide-assists/src/handlers/fill_record_pattern_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,84 @@ fn foo(bar: Bar) {
)
}

#[test]
fn fill_fields_struct_generated_by_macro() {
check_assist(
fill_record_pattern_fields,
r#"
macro_rules! position {
($t: ty) => {
struct Pos {x: $t, y: $t}
};
}
position!(usize);
fn macro_call(pos: Pos) {
let Pos { ..$0 } = pos;
}
"#,
r#"
macro_rules! position {
($t: ty) => {
struct Pos {x: $t, y: $t}
};
}
position!(usize);
fn macro_call(pos: Pos) {
let Pos { x, y } = pos;
}
"#,
);
}

#[test]
fn fill_fields_enum_generated_by_macro() {
check_assist(
fill_record_pattern_fields,
r#"
macro_rules! enum_gen {
($t: ty) => {
enum Foo {
A($t),
B{x: $t, y: $t},
}
};
}
enum_gen!(usize);
fn macro_call(foo: Foo) {
match foo {
Foo::A(_) => false,
Foo::B{ ..$0 } => true,
}
}
"#,
r#"
macro_rules! enum_gen {
($t: ty) => {
enum Foo {
A($t),
B{x: $t, y: $t},
}
};
}
enum_gen!(usize);
fn macro_call(foo: Foo) {
match foo {
Foo::A(_) => false,
Foo::B{ x, y } => true,
}
}
"#,
);
}

#[test]
fn not_applicable_when_not_in_ellipsis() {
check_assist_not_applicable(
Expand Down

0 comments on commit 8fa903a

Please sign in to comment.