Test fill_match_arms
for lazy computation.
This also adds `ide_assists::tests::check_assist_unresolved` function.
This commit is contained in:
parent
570eff6552
commit
d5c96672aa
@ -105,6 +105,7 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<
|
||||
let missing_pats = variants_of_enums
|
||||
.into_iter()
|
||||
.multi_cartesian_product()
|
||||
.inspect(|_| cov_mark::hit!(fill_match_arms_lazy_computation))
|
||||
.map(|variants| {
|
||||
let patterns =
|
||||
variants.into_iter().filter_map(|variant| build_pat(ctx.db(), module, variant));
|
||||
@ -279,7 +280,9 @@ fn build_pat(db: &RootDatabase, module: hir::Module, var: ExtendedVariant) -> Op
|
||||
mod tests {
|
||||
use ide_db::helpers::FamousDefs;
|
||||
|
||||
use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target};
|
||||
use crate::tests::{
|
||||
check_assist, check_assist_not_applicable, check_assist_target, check_assist_unresolved,
|
||||
};
|
||||
|
||||
use super::fill_match_arms;
|
||||
|
||||
@ -1058,4 +1061,19 @@ fn foo(t: Test) {
|
||||
}"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lazy_computation() {
|
||||
// Computing a single missing arm is enough to determine applicability of the assist.
|
||||
cov_mark::check_count!(fill_match_arms_lazy_computation, 1);
|
||||
check_assist_unresolved(
|
||||
fill_match_arms,
|
||||
r#"
|
||||
enum A { One, Two, }
|
||||
fn foo(tuple: (A, A)) {
|
||||
match $0tuple {};
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,12 @@ pub(crate) fn check_assist_not_applicable(assist: Handler, ra_fixture: &str) {
|
||||
check(assist, ra_fixture, ExpectedResult::NotApplicable, None);
|
||||
}
|
||||
|
||||
/// Check assist in unresolved state. Useful to check assists for lazy computation.
|
||||
#[track_caller]
|
||||
pub(crate) fn check_assist_unresolved(assist: Handler, ra_fixture: &str) {
|
||||
check(assist, ra_fixture, ExpectedResult::Unresolved, None);
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn check_doc_test(assist_id: &str, before: &str, after: &str) {
|
||||
let after = trim_indent(after);
|
||||
@ -97,6 +103,7 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) {
|
||||
|
||||
enum ExpectedResult<'a> {
|
||||
NotApplicable,
|
||||
Unresolved,
|
||||
After(&'a str),
|
||||
Target(&'a str),
|
||||
}
|
||||
@ -111,7 +118,11 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label:
|
||||
let sema = Semantics::new(&db);
|
||||
let config = TEST_CONFIG;
|
||||
let ctx = AssistContext::new(sema, &config, frange);
|
||||
let mut acc = Assists::new(&ctx, AssistResolveStrategy::All);
|
||||
let resolve = match expected {
|
||||
ExpectedResult::Unresolved => AssistResolveStrategy::None,
|
||||
_ => AssistResolveStrategy::All,
|
||||
};
|
||||
let mut acc = Assists::new(&ctx, resolve);
|
||||
handler(&mut acc, &ctx);
|
||||
let mut res = acc.finish();
|
||||
|
||||
@ -159,8 +170,14 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label:
|
||||
let range = assist.target;
|
||||
assert_eq_text!(&text_without_caret[range], target);
|
||||
}
|
||||
(Some(assist), ExpectedResult::Unresolved) => assert!(
|
||||
assist.source_change.is_none(),
|
||||
"unresolved assist should not contain source changes"
|
||||
),
|
||||
(Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"),
|
||||
(None, ExpectedResult::After(_)) | (None, ExpectedResult::Target(_)) => {
|
||||
(None, ExpectedResult::After(_))
|
||||
| (None, ExpectedResult::Target(_))
|
||||
| (None, ExpectedResult::Unresolved) => {
|
||||
panic!("code action is not applicable")
|
||||
}
|
||||
(None, ExpectedResult::NotApplicable) => (),
|
||||
|
Loading…
x
Reference in New Issue
Block a user