fix: add test for missing case in bool_to_enum

This commit is contained in:
Ryan Mehri 2023-10-27 07:58:33 -07:00 committed by Lukas Wirth
parent a8d935eedc
commit 2034556f81

View File

@ -405,13 +405,12 @@ fn find_record_expr_usage(
let record_field = ast::RecordExprField::for_field_name(name_ref)?;
let initializer = record_field.expr()?;
if let Definition::Field(expected_field) = target_definition {
if got_field != expected_field {
return None;
match target_definition {
Definition::Field(expected_field) if got_field == expected_field => {
Some((record_field, initializer))
}
_ => None,
}
Some((record_field, initializer))
}
fn find_record_pat_field_usage(name: &ast::NameLike) -> Option<ast::Pat> {
@ -800,6 +799,36 @@ fn main() {
)
}
#[test]
fn local_var_init_struct_usage() {
check_assist(
bool_to_enum,
r#"
struct Foo {
foo: bool,
}
fn main() {
let $0foo = true;
let s = Foo { foo };
}
"#,
r#"
struct Foo {
foo: bool,
}
#[derive(PartialEq, Eq)]
enum Bool { True, False }
fn main() {
let foo = Bool::True;
let s = Foo { foo: foo == Bool::True };
}
"#,
)
}
#[test]
fn field_struct_basic() {
cov_mark::check!(replaces_record_expr);