diff options
Diffstat (limited to 'crates/ra_ide_api/tests/test')
-rw-r--r-- | crates/ra_ide_api/tests/test/main.rs | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/crates/ra_ide_api/tests/test/main.rs b/crates/ra_ide_api/tests/test/main.rs index 2b863aedf..4aa13b0e7 100644 --- a/crates/ra_ide_api/tests/test/main.rs +++ b/crates/ra_ide_api/tests/test/main.rs | |||
@@ -1,11 +1,13 @@ | |||
1 | use ra_ide_api::{ | ||
2 | AnalysisChange, | ||
3 | CrateGraph, FileId, mock_analysis::{MockAnalysis, single_file, single_file_with_position}, Query, | ||
4 | }; | ||
5 | use ra_ide_api::mock_analysis::analysis_and_position; | ||
1 | use ra_syntax::TextRange; | 6 | use ra_syntax::TextRange; |
2 | use test_utils::assert_eq_text; | 7 | use test_utils::assert_eq_text; |
3 | use insta::assert_debug_snapshot_matches; | 8 | use insta::assert_debug_snapshot_matches; |
4 | 9 | ||
5 | use ra_ide_api::{ | 10 | mod runnables; |
6 | mock_analysis::{single_file, single_file_with_position, MockAnalysis}, | ||
7 | AnalysisChange, CrateGraph, FileId, Query | ||
8 | }; | ||
9 | 11 | ||
10 | #[test] | 12 | #[test] |
11 | fn test_unresolved_module_diagnostic() { | 13 | fn test_unresolved_module_diagnostic() { |
@@ -91,6 +93,7 @@ fn test_find_all_refs_for_fn_param() { | |||
91 | let refs = get_all_refs(code); | 93 | let refs = get_all_refs(code); |
92 | assert_eq!(refs.len(), 2); | 94 | assert_eq!(refs.len(), 2); |
93 | } | 95 | } |
96 | |||
94 | #[test] | 97 | #[test] |
95 | fn test_rename_for_local() { | 98 | fn test_rename_for_local() { |
96 | test_rename( | 99 | test_rename( |
@@ -167,15 +170,35 @@ fn test_rename_for_mut_param() { | |||
167 | ); | 170 | ); |
168 | } | 171 | } |
169 | 172 | ||
173 | #[test] | ||
174 | fn test_rename_mod() { | ||
175 | let (analysis, position) = analysis_and_position( | ||
176 | " | ||
177 | //- /bar.rs | ||
178 | mod fo<|>o; | ||
179 | //- /bar/foo.rs | ||
180 | // emtpy | ||
181 | ", | ||
182 | ); | ||
183 | let new_name = "foo2"; | ||
184 | let source_change = analysis.rename(position, new_name).unwrap(); | ||
185 | assert_eq_dbg( | ||
186 | r#"Some(SourceChange { label: "rename", source_file_edits: [SourceFileEdit { file_id: FileId(1), edit: TextEdit { atoms: [AtomTextEdit { delete: [4; 7), insert: "foo2" }] } }], file_system_edits: [MoveFile { src: FileId(2), dst_source_root: SourceRootId(0), dst_path: "bar/foo2.rs" }], cursor_position: None })"#, | ||
187 | &source_change, | ||
188 | ); | ||
189 | } | ||
190 | |||
170 | fn test_rename(text: &str, new_name: &str, expected: &str) { | 191 | fn test_rename(text: &str, new_name: &str, expected: &str) { |
171 | let (analysis, position) = single_file_with_position(text); | 192 | let (analysis, position) = single_file_with_position(text); |
172 | let edits = analysis.rename(position, new_name).unwrap(); | 193 | let source_change = analysis.rename(position, new_name).unwrap(); |
173 | let mut text_edit_bulder = ra_text_edit::TextEditBuilder::default(); | 194 | let mut text_edit_bulder = ra_text_edit::TextEditBuilder::default(); |
174 | let mut file_id: Option<FileId> = None; | 195 | let mut file_id: Option<FileId> = None; |
175 | for edit in edits { | 196 | if let Some(change) = source_change { |
176 | file_id = Some(edit.file_id); | 197 | for edit in change.source_file_edits { |
177 | for atom in edit.edit.as_atoms() { | 198 | file_id = Some(edit.file_id); |
178 | text_edit_bulder.replace(atom.delete, atom.insert.clone()); | 199 | for atom in edit.edit.as_atoms() { |
200 | text_edit_bulder.replace(atom.delete, atom.insert.clone()); | ||
201 | } | ||
179 | } | 202 | } |
180 | } | 203 | } |
181 | let result = text_edit_bulder | 204 | let result = text_edit_bulder |