aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/tests.rs')
-rw-r--r--crates/ra_assists/src/tests.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs
index 17e3ece9f..45b2d9733 100644
--- a/crates/ra_assists/src/tests.rs
+++ b/crates/ra_assists/src/tests.rs
@@ -11,7 +11,7 @@ use test_utils::{
11 RangeOrOffset, 11 RangeOrOffset,
12}; 12};
13 13
14use crate::{handlers::Handler, resolved_assists, AssistCtx}; 14use crate::{handlers::Handler, resolved_assists, AssistContext, Assists};
15 15
16pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { 16pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
17 let (mut db, file_id) = RootDatabase::with_single_file(text); 17 let (mut db, file_id) = RootDatabase::with_single_file(text);
@@ -71,7 +71,7 @@ enum ExpectedResult<'a> {
71 Target(&'a str), 71 Target(&'a str),
72} 72}
73 73
74fn check(assist: Handler, before: &str, expected: ExpectedResult) { 74fn check(handler: Handler, before: &str, expected: ExpectedResult) {
75 let (text_without_caret, file_with_caret_id, range_or_offset, db) = if before.contains("//-") { 75 let (text_without_caret, file_with_caret_id, range_or_offset, db) = if before.contains("//-") {
76 let (mut db, position) = RootDatabase::with_position(before); 76 let (mut db, position) = RootDatabase::with_position(before);
77 db.set_local_roots(Arc::new(vec![db.file_source_root(position.file_id)])); 77 db.set_local_roots(Arc::new(vec![db.file_source_root(position.file_id)]));
@@ -90,17 +90,20 @@ fn check(assist: Handler, before: &str, expected: ExpectedResult) {
90 let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() }; 90 let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() };
91 91
92 let sema = Semantics::new(&db); 92 let sema = Semantics::new(&db);
93 let assist_ctx = AssistCtx::new(&sema, frange, true); 93 let ctx = AssistContext::new(sema, frange);
94 94 let mut acc = Assists::new_resolved(&ctx);
95 match (assist(assist_ctx), expected) { 95 handler(&mut acc, &ctx);
96 let mut res = acc.finish_resolved();
97 let assist = res.pop();
98 match (assist, expected) {
96 (Some(assist), ExpectedResult::After(after)) => { 99 (Some(assist), ExpectedResult::After(after)) => {
97 let mut action = assist.0[0].source_change.clone().unwrap(); 100 let mut source_change = assist.source_change;
98 let change = action.source_file_edits.pop().unwrap(); 101 let change = source_change.source_file_edits.pop().unwrap();
99 102
100 let mut actual = db.file_text(change.file_id).as_ref().to_owned(); 103 let mut actual = db.file_text(change.file_id).as_ref().to_owned();
101 change.edit.apply(&mut actual); 104 change.edit.apply(&mut actual);
102 105
103 match action.cursor_position { 106 match source_change.cursor_position {
104 None => { 107 None => {
105 if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset { 108 if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset {
106 let off = change 109 let off = change
@@ -116,7 +119,7 @@ fn check(assist: Handler, before: &str, expected: ExpectedResult) {
116 assert_eq_text!(after, &actual); 119 assert_eq_text!(after, &actual);
117 } 120 }
118 (Some(assist), ExpectedResult::Target(target)) => { 121 (Some(assist), ExpectedResult::Target(target)) => {
119 let range = assist.0[0].label.target; 122 let range = assist.label.target;
120 assert_eq_text!(&text_without_caret[range], target); 123 assert_eq_text!(&text_without_caret[range], target);
121 } 124 }
122 (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"), 125 (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"),