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.rs40
1 files changed, 17 insertions, 23 deletions
diff --git a/crates/assists/src/tests.rs b/crates/assists/src/tests.rs
index fef29a0b8..71431b406 100644
--- a/crates/assists/src/tests.rs
+++ b/crates/assists/src/tests.rs
@@ -80,10 +80,8 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) {
80 let actual = { 80 let actual = {
81 let source_change = assist.source_change.unwrap(); 81 let source_change = assist.source_change.unwrap();
82 let mut actual = before; 82 let mut actual = before;
83 for source_file_edit in source_change.source_file_edits { 83 if let Some(source_file_edit) = source_change.get_source_edit(file_id) {
84 if source_file_edit.file_id == file_id { 84 source_file_edit.apply(&mut actual);
85 source_file_edit.edit.apply(&mut actual)
86 }
87 } 85 }
88 actual 86 actual
89 }; 87 };
@@ -116,37 +114,33 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label:
116 114
117 match (assist, expected) { 115 match (assist, expected) {
118 (Some(assist), ExpectedResult::After(after)) => { 116 (Some(assist), ExpectedResult::After(after)) => {
119 let mut source_change = assist.source_change.unwrap(); 117 let source_change = assist.source_change.unwrap();
120 assert!(!source_change.source_file_edits.is_empty()); 118 assert!(!source_change.source_file_edits.is_empty());
121 let skip_header = source_change.source_file_edits.len() == 1 119 let skip_header = source_change.source_file_edits.len() == 1
122 && source_change.file_system_edits.len() == 0; 120 && source_change.file_system_edits.len() == 0;
123 source_change.source_file_edits.sort_by_key(|it| it.file_id);
124 121
125 let mut buf = String::new(); 122 let mut buf = String::new();
126 for source_file_edit in source_change.source_file_edits { 123 for (file_id, edit) in source_change.source_file_edits {
127 let mut text = db.file_text(source_file_edit.file_id).as_ref().to_owned(); 124 let mut text = db.file_text(file_id).as_ref().to_owned();
128 source_file_edit.edit.apply(&mut text); 125 edit.apply(&mut text);
129 if !skip_header { 126 if !skip_header {
130 let sr = db.file_source_root(source_file_edit.file_id); 127 let sr = db.file_source_root(file_id);
131 let sr = db.source_root(sr); 128 let sr = db.source_root(sr);
132 let path = sr.path_for_file(&source_file_edit.file_id).unwrap(); 129 let path = sr.path_for_file(&file_id).unwrap();
133 format_to!(buf, "//- {}\n", path) 130 format_to!(buf, "//- {}\n", path)
134 } 131 }
135 buf.push_str(&text); 132 buf.push_str(&text);
136 } 133 }
137 134
138 for file_system_edit in source_change.file_system_edits.clone() { 135 for file_system_edit in source_change.file_system_edits {
139 match file_system_edit { 136 if let FileSystemEdit::CreateFile { dst, initial_contents } = file_system_edit {
140 FileSystemEdit::CreateFile { dst, initial_contents } => { 137 let sr = db.file_source_root(dst.anchor);
141 let sr = db.file_source_root(dst.anchor); 138 let sr = db.source_root(sr);
142 let sr = db.source_root(sr); 139 let mut base = sr.path_for_file(&dst.anchor).unwrap().clone();
143 let mut base = sr.path_for_file(&dst.anchor).unwrap().clone(); 140 base.pop();
144 base.pop(); 141 let created_file_path = format!("{}{}", base.to_string(), &dst.path[1..]);
145 let created_file_path = format!("{}{}", base.to_string(), &dst.path[1..]); 142 format_to!(buf, "//- {}\n", created_file_path);
146 format_to!(buf, "//- {}\n", created_file_path); 143 buf.push_str(&initial_contents);
147 buf.push_str(&initial_contents);
148 }
149 _ => (),
150 } 144 }
151 } 145 }
152 146