fix: correct broken logic for return complition
It seems that we've accidentally deleted the tests here couple of years ago, and then fairly recently made a typo during refactor as well. Reinstall tests, with coverage marks this time :-)
This commit is contained in:
parent
8ddb8b7e8e
commit
d7ef3f51ec
2 changed files with 55 additions and 7 deletions
|
@ -282,14 +282,26 @@ pub(crate) fn complete_expr_path(
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(ty) = innermost_ret_ty {
|
||||
if let Some(ret_ty) = innermost_ret_ty {
|
||||
add_keyword(
|
||||
"return",
|
||||
match (in_block_expr, ty.is_unit()) {
|
||||
(true, true) => "return ;",
|
||||
(true, false) => "return;",
|
||||
(false, true) => "return $0",
|
||||
(false, false) => "return",
|
||||
match (ret_ty.is_unit(), in_block_expr) {
|
||||
(true, true) => {
|
||||
cov_mark::hit!(return_unit_block);
|
||||
"return;"
|
||||
}
|
||||
(true, false) => {
|
||||
cov_mark::hit!(return_unit_no_block);
|
||||
"return"
|
||||
}
|
||||
(false, true) => {
|
||||
cov_mark::hit!(return_value_block);
|
||||
"return $0;"
|
||||
}
|
||||
(false, false) => {
|
||||
cov_mark::hit!(return_value_no_block);
|
||||
"return $0"
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Completion tests for expressions.
|
||||
use expect_test::{expect, Expect};
|
||||
|
||||
use crate::tests::{completion_list, BASE_ITEMS_FIXTURE};
|
||||
use crate::tests::{check_edit, completion_list, BASE_ITEMS_FIXTURE};
|
||||
|
||||
fn check(ra_fixture: &str, expect: Expect) {
|
||||
let actual = completion_list(&format!("{}{}", BASE_ITEMS_FIXTURE, ra_fixture));
|
||||
|
@ -670,3 +670,39 @@ fn main() {
|
|||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_unit_block() {
|
||||
cov_mark::check!(return_unit_block);
|
||||
check_edit("return", r#"fn f() { if true { $0 } }"#, r#"fn f() { if true { return; } }"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_unit_no_block() {
|
||||
cov_mark::check!(return_unit_no_block);
|
||||
check_edit(
|
||||
"return",
|
||||
r#"fn f() { match () { () => $0 } }"#,
|
||||
r#"fn f() { match () { () => return } }"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_value_block() {
|
||||
cov_mark::check!(return_value_block);
|
||||
check_edit(
|
||||
"return",
|
||||
r#"fn f() -> i32 { if true { $0 } }"#,
|
||||
r#"fn f() -> i32 { if true { return $0; } }"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_value_no_block() {
|
||||
cov_mark::check!(return_value_no_block);
|
||||
check_edit(
|
||||
"return",
|
||||
r#"fn f() -> i32 { match () { () => $0 } }"#,
|
||||
r#"fn f() -> i32 { match () { () => return $0 } }"#,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue