aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists/src/tests.rs')
-rw-r--r--crates/assists/src/tests.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/crates/assists/src/tests.rs b/crates/assists/src/tests.rs
index 849d85e76..709a34d03 100644
--- a/crates/assists/src/tests.rs
+++ b/crates/assists/src/tests.rs
@@ -7,7 +7,7 @@ use syntax::TextRange;
7use test_utils::{assert_eq_text, extract_offset, extract_range}; 7use test_utils::{assert_eq_text, extract_offset, extract_range};
8 8
9use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, Assists}; 9use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, Assists};
10use stdx::trim_indent; 10use stdx::{format_to, trim_indent};
11 11
12pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { 12pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
13 RootDatabase::with_single_file(text) 13 RootDatabase::with_single_file(text)
@@ -98,11 +98,24 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label:
98 match (assist, expected) { 98 match (assist, expected) {
99 (Some(assist), ExpectedResult::After(after)) => { 99 (Some(assist), ExpectedResult::After(after)) => {
100 let mut source_change = assist.source_change; 100 let mut source_change = assist.source_change;
101 let change = source_change.source_file_edits.pop().unwrap(); 101 assert!(!source_change.source_file_edits.is_empty());
102 102 let skip_header = source_change.source_file_edits.len() == 1;
103 let mut actual = db.file_text(change.file_id).as_ref().to_owned(); 103 source_change.source_file_edits.sort_by_key(|it| it.file_id);
104 change.edit.apply(&mut actual); 104
105 assert_eq_text!(after, &actual); 105 let mut buf = String::new();
106 for source_file_edit in source_change.source_file_edits {
107 let mut text = db.file_text(source_file_edit.file_id).as_ref().to_owned();
108 source_file_edit.edit.apply(&mut text);
109 if !skip_header {
110 let sr = db.file_source_root(source_file_edit.file_id);
111 let sr = db.source_root(sr);
112 let path = sr.path_for_file(&source_file_edit.file_id).unwrap();
113 format_to!(buf, "//- {}\n", path)
114 }
115 buf.push_str(&text);
116 }
117
118 assert_eq_text!(after, &buf);
106 } 119 }
107 (Some(assist), ExpectedResult::Target(target)) => { 120 (Some(assist), ExpectedResult::Target(target)) => {
108 let range = assist.assist.target; 121 let range = assist.assist.target;