aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/tests/test
diff options
context:
space:
mode:
authorgfreezy <[email protected]>2019-01-14 16:09:03 +0000
committerAleksey Kladov <[email protected]>2019-01-19 12:36:58 +0000
commitbc0f79f74ad0ab4f663b94772ccbfabed1de625e (patch)
tree21c125b75a7b757435ce641788cdcde0b9dd4f14 /crates/ra_ide_api/tests/test
parentb82fe73d1ab9727ff650382d9c86a231b06245be (diff)
rename mod
Diffstat (limited to 'crates/ra_ide_api/tests/test')
-rw-r--r--crates/ra_ide_api/tests/test/main.rs41
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 @@
1use ra_ide_api::{
2 AnalysisChange,
3 CrateGraph, FileId, mock_analysis::{MockAnalysis, single_file, single_file_with_position}, Query,
4};
5use ra_ide_api::mock_analysis::analysis_and_position;
1use ra_syntax::TextRange; 6use ra_syntax::TextRange;
2use test_utils::assert_eq_text; 7use test_utils::assert_eq_text;
3use insta::assert_debug_snapshot_matches; 8use insta::assert_debug_snapshot_matches;
4 9
5use ra_ide_api::{ 10mod runnables;
6 mock_analysis::{single_file, single_file_with_position, MockAnalysis},
7 AnalysisChange, CrateGraph, FileId, Query
8};
9 11
10#[test] 12#[test]
11fn test_unresolved_module_diagnostic() { 13fn 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]
95fn test_rename_for_local() { 98fn 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]
174fn 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
170fn test_rename(text: &str, new_name: &str, expected: &str) { 191fn 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