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.rs30
1 files changed, 8 insertions, 22 deletions
diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs
index a3eacb8f1..62dd3547f 100644
--- a/crates/ra_assists/src/tests.rs
+++ b/crates/ra_assists/src/tests.rs
@@ -7,11 +7,10 @@ use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt};
7use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase}; 7use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase};
8use ra_syntax::TextRange; 8use ra_syntax::TextRange;
9use test_utils::{ 9use test_utils::{
10 add_cursor, assert_eq_text, extract_offset, extract_range, extract_range_or_offset, 10 assert_eq_text, extract_offset, extract_range, extract_range_or_offset, RangeOrOffset,
11 RangeOrOffset,
12}; 11};
13 12
14use crate::{handlers::Handler, Assist, AssistContext, Assists}; 13use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, Assists};
15 14
16pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { 15pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
17 let (mut db, file_id) = RootDatabase::with_single_file(text); 16 let (mut db, file_id) = RootDatabase::with_single_file(text);
@@ -41,14 +40,14 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) {
41 let (db, file_id) = crate::tests::with_single_file(&before); 40 let (db, file_id) = crate::tests::with_single_file(&before);
42 let frange = FileRange { file_id, range: selection.into() }; 41 let frange = FileRange { file_id, range: selection.into() };
43 42
44 let mut assist = Assist::resolved(&db, frange) 43 let mut assist = Assist::resolved(&db, &AssistConfig::default(), frange)
45 .into_iter() 44 .into_iter()
46 .find(|assist| assist.assist.id.0 == assist_id) 45 .find(|assist| assist.assist.id.0 == assist_id)
47 .unwrap_or_else(|| { 46 .unwrap_or_else(|| {
48 panic!( 47 panic!(
49 "\n\nAssist is not applicable: {}\nAvailable assists: {}", 48 "\n\nAssist is not applicable: {}\nAvailable assists: {}",
50 assist_id, 49 assist_id,
51 Assist::resolved(&db, frange) 50 Assist::resolved(&db, &AssistConfig::default(), frange)
52 .into_iter() 51 .into_iter()
53 .map(|assist| assist.assist.id.0) 52 .map(|assist| assist.assist.id.0)
54 .collect::<Vec<_>>() 53 .collect::<Vec<_>>()
@@ -90,7 +89,8 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult) {
90 let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() }; 89 let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() };
91 90
92 let sema = Semantics::new(&db); 91 let sema = Semantics::new(&db);
93 let ctx = AssistContext::new(sema, frange); 92 let config = AssistConfig::default();
93 let ctx = AssistContext::new(sema, &config, frange);
94 let mut acc = Assists::new_resolved(&ctx); 94 let mut acc = Assists::new_resolved(&ctx);
95 handler(&mut acc, &ctx); 95 handler(&mut acc, &ctx);
96 let mut res = acc.finish_resolved(); 96 let mut res = acc.finish_resolved();
@@ -102,20 +102,6 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult) {
102 102
103 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();
104 change.edit.apply(&mut actual); 104 change.edit.apply(&mut actual);
105
106 match source_change.cursor_position {
107 None => {
108 if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset {
109 let off = change
110 .edit
111 .apply_to_offset(before_cursor_pos)
112 .expect("cursor position is affected by the edit");
113 actual = add_cursor(&actual, off)
114 }
115 }
116 Some(off) => actual = add_cursor(&actual, off.offset),
117 };
118
119 assert_eq_text!(after, &actual); 105 assert_eq_text!(after, &actual);
120 } 106 }
121 (Some(assist), ExpectedResult::Target(target)) => { 107 (Some(assist), ExpectedResult::Target(target)) => {
@@ -136,7 +122,7 @@ fn assist_order_field_struct() {
136 let (before_cursor_pos, before) = extract_offset(before); 122 let (before_cursor_pos, before) = extract_offset(before);
137 let (db, file_id) = with_single_file(&before); 123 let (db, file_id) = with_single_file(&before);
138 let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) }; 124 let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) };
139 let assists = Assist::resolved(&db, frange); 125 let assists = Assist::resolved(&db, &AssistConfig::default(), frange);
140 let mut assists = assists.iter(); 126 let mut assists = assists.iter();
141 127
142 assert_eq!( 128 assert_eq!(
@@ -159,7 +145,7 @@ fn assist_order_if_expr() {
159 let (range, before) = extract_range(before); 145 let (range, before) = extract_range(before);
160 let (db, file_id) = with_single_file(&before); 146 let (db, file_id) = with_single_file(&before);
161 let frange = FileRange { file_id, range }; 147 let frange = FileRange { file_id, range };
162 let assists = Assist::resolved(&db, frange); 148 let assists = Assist::resolved(&db, &AssistConfig::default(), frange);
163 let mut assists = assists.iter(); 149 let mut assists = assists.iter();
164 150
165 assert_eq!(assists.next().expect("expected assist").assist.label, "Extract into variable"); 151 assert_eq!(assists.next().expect("expected assist").assist.label, "Extract into variable");