aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_assists/src/tests.rs')
-rw-r--r--crates/ide_assists/src/tests.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/crates/ide_assists/src/tests.rs b/crates/ide_assists/src/tests.rs
index 0d3969c36..b091ab91a 100644
--- a/crates/ide_assists/src/tests.rs
+++ b/crates/ide_assists/src/tests.rs
@@ -61,6 +61,12 @@ pub(crate) fn check_assist_not_applicable(assist: Handler, ra_fixture: &str) {
61 check(assist, ra_fixture, ExpectedResult::NotApplicable, None); 61 check(assist, ra_fixture, ExpectedResult::NotApplicable, None);
62} 62}
63 63
64/// Check assist in unresolved state. Useful to check assists for lazy computation.
65#[track_caller]
66pub(crate) fn check_assist_unresolved(assist: Handler, ra_fixture: &str) {
67 check(assist, ra_fixture, ExpectedResult::Unresolved, None);
68}
69
64#[track_caller] 70#[track_caller]
65fn check_doc_test(assist_id: &str, before: &str, after: &str) { 71fn check_doc_test(assist_id: &str, before: &str, after: &str) {
66 let after = trim_indent(after); 72 let after = trim_indent(after);
@@ -97,6 +103,7 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) {
97 103
98enum ExpectedResult<'a> { 104enum ExpectedResult<'a> {
99 NotApplicable, 105 NotApplicable,
106 Unresolved,
100 After(&'a str), 107 After(&'a str),
101 Target(&'a str), 108 Target(&'a str),
102} 109}
@@ -111,7 +118,11 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label:
111 let sema = Semantics::new(&db); 118 let sema = Semantics::new(&db);
112 let config = TEST_CONFIG; 119 let config = TEST_CONFIG;
113 let ctx = AssistContext::new(sema, &config, frange); 120 let ctx = AssistContext::new(sema, &config, frange);
114 let mut acc = Assists::new(&ctx, AssistResolveStrategy::All); 121 let resolve = match expected {
122 ExpectedResult::Unresolved => AssistResolveStrategy::None,
123 _ => AssistResolveStrategy::All,
124 };
125 let mut acc = Assists::new(&ctx, resolve);
115 handler(&mut acc, &ctx); 126 handler(&mut acc, &ctx);
116 let mut res = acc.finish(); 127 let mut res = acc.finish();
117 128
@@ -159,8 +170,14 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label:
159 let range = assist.target; 170 let range = assist.target;
160 assert_eq_text!(&text_without_caret[range], target); 171 assert_eq_text!(&text_without_caret[range], target);
161 } 172 }
173 (Some(assist), ExpectedResult::Unresolved) => assert!(
174 assist.source_change.is_none(),
175 "unresolved assist should not contain source changes"
176 ),
162 (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"), 177 (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"),
163 (None, ExpectedResult::After(_)) | (None, ExpectedResult::Target(_)) => { 178 (None, ExpectedResult::After(_))
179 | (None, ExpectedResult::Target(_))
180 | (None, ExpectedResult::Unresolved) => {
164 panic!("code action is not applicable") 181 panic!("code action is not applicable")
165 } 182 }
166 (None, ExpectedResult::NotApplicable) => (), 183 (None, ExpectedResult::NotApplicable) => (),