Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/context/tests.rs')
| -rw-r--r-- | crates/ide-completion/src/context/tests.rs | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/crates/ide-completion/src/context/tests.rs b/crates/ide-completion/src/context/tests.rs index 41f0db3c52..e97d9720e3 100644 --- a/crates/ide-completion/src/context/tests.rs +++ b/crates/ide-completion/src/context/tests.rs @@ -147,6 +147,18 @@ fn bar(x: &u32) {} } #[test] +fn expected_type_fn_param_deref() { + cov_mark::check!(expected_type_fn_param_deref); + check_expected_type_and_name( + r#" +fn foo() { bar(*$0); } +fn bar(x: &u32) {} +"#, + expect!["ty: &'_ &'_ u32, name: x"], + ); +} + +#[test] fn expected_type_struct_field_without_leading_char() { cov_mark::check!(expected_type_struct_field_without_leading_char); check_expected_type_and_name( @@ -245,6 +257,22 @@ fn foo() -> Foo { } #[test] +fn expected_type_match_arm_block_body_without_leading_char() { + cov_mark::check!(expected_type_match_arm_body_without_leading_char); + cov_mark::check!(expected_type_match_arm_body_with_leading_char); + check_expected_type_and_name( + r#" +struct Foo; +enum E { X } +fn foo() -> Foo { + match E::X { Foo::X => { $0 } } +} +"#, + expect![[r#"ty: Foo, name: ?"#]], + ); +} + +#[test] fn expected_type_match_body_arm_with_leading_char() { cov_mark::check!(expected_type_match_arm_body_with_leading_char); check_expected_type_and_name( @@ -608,6 +636,125 @@ fn foo() { } #[test] +fn expected_type_break_expr_in_loop() { + check_expected_type_and_name( + r#" +enum State { Stop } +fn foo() { + let _x: State = loop { + { + break State::Stop; + break $0; + } + }; +} +"#, + expect![[r#"ty: State, name: ?"#]], + ); + + check_expected_type_and_name( + r#" +enum State { Stop } +fn foo() { + let _x: State = 'a: loop { + { + break State::Stop; + break $0; + } + }; +} +"#, + expect![[r#"ty: State, name: ?"#]], + ); + + check_expected_type_and_name( + r#" +enum State { Stop } +fn foo() { + let _x: State = 'a: loop { + while true { + break $0; + } + }; +} +"#, + expect![[r#"ty: (), name: ?"#]], + ); +} + +#[test] +fn expected_type_break_expr_in_labeled_loop() { + check_expected_type_and_name( + r#" +enum State { Stop } +fn foo() { + let _x: State = 'a: loop { + let _y: i32 = loop { + { + break 'a State::Stop; + break 'a $0; + } + }; + }; +} +"#, + expect![[r#"ty: State, name: ?"#]], + ); + + check_expected_type_and_name( + r#" +enum State { Stop } +fn foo() { + let _x: State = 'a: loop { + let _y: i32 = loop { + while true { + break 'a State::Stop; + break 'a $0; + } + }; + }; +} +"#, + expect![[r#"ty: State, name: ?"#]], + ); + + check_expected_type_and_name( + r#" +enum State { Stop } +fn foo() { + 'a: while true { + let _x: State = loop { + break State::Stop; + break 'a $0; + }; + } +} +"#, + expect![[r#"ty: (), name: ?"#]], + ); +} + +#[test] +fn expected_type_break_expr_in_labeled_block() { + check_expected_type_and_name( + r#" +enum State { Stop } +fn foo() { + let _x: State = 'a: { + let _y: i32 = 'b: { + { + break 'a State::Stop; + break 'a $0; + }; + }; + }; +} +"#, + expect![[r#"ty: State, name: ?"#]], + ); +} + +#[test] fn expected_type_logic_op() { check_expected_type_and_name( r#" |