aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/tests.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-06 14:49:34 +0100
committerGitHub <[email protected]>2020-05-06 14:49:34 +0100
commitefd8e34c396f1524623a495e47111f1047cf2879 (patch)
tree44ebb47b92d71a5e30cb469988ff1b490ca856d8 /crates/ra_assists/src/tests.rs
parent1116c9a0e9992d0dea8dac87de95c8a74c093cff (diff)
parentfdd4df97ba5ce1f59abf9e945052fc6f3e077c3a (diff)
Merge #4344
4344: Use SourceChange for assists r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/tests.rs')
-rw-r--r--crates/ra_assists/src/tests.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs
index dd9026df6..572462bfc 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, AssistFile}; 14use crate::{handlers::Handler, resolved_assists, AssistCtx};
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);
@@ -41,7 +41,7 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) {
41 let (db, file_id) = crate::tests::with_single_file(&before); 41 let (db, file_id) = crate::tests::with_single_file(&before);
42 let frange = FileRange { file_id, range: selection.into() }; 42 let frange = FileRange { file_id, range: selection.into() };
43 43
44 let assist = resolved_assists(&db, frange) 44 let mut assist = resolved_assists(&db, frange)
45 .into_iter() 45 .into_iter()
46 .find(|assist| assist.label.id.0 == assist_id) 46 .find(|assist| assist.label.id.0 == assist_id)
47 .unwrap_or_else(|| { 47 .unwrap_or_else(|| {
@@ -57,8 +57,9 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) {
57 }); 57 });
58 58
59 let actual = { 59 let actual = {
60 let change = assist.action.source_file_edits.pop().unwrap();
60 let mut actual = before.clone(); 61 let mut actual = before.clone();
61 assist.action.edit.apply(&mut actual); 62 change.edit.apply(&mut actual);
62 actual 63 actual
63 }; 64 };
64 assert_eq_text!(after, &actual); 65 assert_eq_text!(after, &actual);
@@ -93,26 +94,23 @@ fn check(assist: Handler, before: &str, expected: ExpectedResult) {
93 94
94 match (assist(assist_ctx), expected) { 95 match (assist(assist_ctx), expected) {
95 (Some(assist), ExpectedResult::After(after)) => { 96 (Some(assist), ExpectedResult::After(after)) => {
96 let action = assist.0[0].action.clone().unwrap(); 97 let mut action = assist.0[0].action.clone().unwrap();
98 let change = action.source_file_edits.pop().unwrap();
97 99
98 let mut actual = if let AssistFile::TargetFile(file_id) = action.file { 100 let mut actual = db.file_text(change.file_id).as_ref().to_owned();
99 db.file_text(file_id).as_ref().to_owned() 101 change.edit.apply(&mut actual);
100 } else {
101 text_without_caret
102 };
103 action.edit.apply(&mut actual);
104 102
105 match action.cursor_position { 103 match action.cursor_position {
106 None => { 104 None => {
107 if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset { 105 if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset {
108 let off = action 106 let off = change
109 .edit 107 .edit
110 .apply_to_offset(before_cursor_pos) 108 .apply_to_offset(before_cursor_pos)
111 .expect("cursor position is affected by the edit"); 109 .expect("cursor position is affected by the edit");
112 actual = add_cursor(&actual, off) 110 actual = add_cursor(&actual, off)
113 } 111 }
114 } 112 }
115 Some(off) => actual = add_cursor(&actual, off), 113 Some(off) => actual = add_cursor(&actual, off.offset),
116 }; 114 };
117 115
118 assert_eq_text!(after, &actual); 116 assert_eq_text!(after, &actual);