aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/tests/test/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/tests/test/main.rs')
-rw-r--r--crates/ra_ide_api/tests/test/main.rs127
1 files changed, 0 insertions, 127 deletions
diff --git a/crates/ra_ide_api/tests/test/main.rs b/crates/ra_ide_api/tests/test/main.rs
index 2077a89ce..756075190 100644
--- a/crates/ra_ide_api/tests/test/main.rs
+++ b/crates/ra_ide_api/tests/test/main.rs
@@ -2,9 +2,7 @@ use ra_ide_api::{
2 AnalysisChange, 2 AnalysisChange,
3 CrateGraph, FileId, mock_analysis::{MockAnalysis, single_file, single_file_with_position}, Query, 3 CrateGraph, FileId, mock_analysis::{MockAnalysis, single_file, single_file_with_position}, Query,
4}; 4};
5use ra_ide_api::mock_analysis::analysis_and_position;
6use ra_syntax::TextRange; 5use ra_syntax::TextRange;
7use test_utils::assert_eq_text;
8use insta::assert_debug_snapshot_matches; 6use insta::assert_debug_snapshot_matches;
9 7
10#[test] 8#[test]
@@ -93,131 +91,6 @@ fn test_find_all_refs_for_fn_param() {
93} 91}
94 92
95#[test] 93#[test]
96fn test_rename_for_local() {
97 test_rename(
98 r#"
99 fn main() {
100 let mut i = 1;
101 let j = 1;
102 i = i<|> + j;
103
104 {
105 i = 0;
106 }
107
108 i = 5;
109 }"#,
110 "k",
111 r#"
112 fn main() {
113 let mut k = 1;
114 let j = 1;
115 k = k + j;
116
117 {
118 k = 0;
119 }
120
121 k = 5;
122 }"#,
123 );
124}
125
126#[test]
127fn test_rename_for_param_inside() {
128 test_rename(
129 r#"
130 fn foo(i : u32) -> u32 {
131 i<|>
132 }"#,
133 "j",
134 r#"
135 fn foo(j : u32) -> u32 {
136 j
137 }"#,
138 );
139}
140
141#[test]
142fn test_rename_refs_for_fn_param() {
143 test_rename(
144 r#"
145 fn foo(i<|> : u32) -> u32 {
146 i
147 }"#,
148 "new_name",
149 r#"
150 fn foo(new_name : u32) -> u32 {
151 new_name
152 }"#,
153 );
154}
155
156#[test]
157fn test_rename_for_mut_param() {
158 test_rename(
159 r#"
160 fn foo(mut i<|> : u32) -> u32 {
161 i
162 }"#,
163 "new_name",
164 r#"
165 fn foo(mut new_name : u32) -> u32 {
166 new_name
167 }"#,
168 );
169}
170
171#[test]
172fn test_rename_mod() {
173 let (analysis, position) = analysis_and_position(
174 "
175 //- /bar.rs
176 mod fo<|>o;
177 //- /bar/foo.rs
178 // emtpy
179 ",
180 );
181 let new_name = "foo2";
182 let source_change = analysis.rename(position, new_name).unwrap();
183 assert_debug_snapshot_matches!("rename_mod", &source_change);
184}
185
186#[test]
187fn test_rename_mod_in_dir() {
188 let (analysis, position) = analysis_and_position(
189 "
190 //- /lib.rs
191 mod fo<|>o;
192 //- /foo/mod.rs
193 // emtpy
194 ",
195 );
196 let new_name = "foo2";
197 let source_change = analysis.rename(position, new_name).unwrap();
198 assert_debug_snapshot_matches!("rename_mod_in_dir", &source_change);
199}
200
201fn test_rename(text: &str, new_name: &str, expected: &str) {
202 let (analysis, position) = single_file_with_position(text);
203 let source_change = analysis.rename(position, new_name).unwrap();
204 let mut text_edit_bulder = ra_text_edit::TextEditBuilder::default();
205 let mut file_id: Option<FileId> = None;
206 if let Some(change) = source_change {
207 for edit in change.source_file_edits {
208 file_id = Some(edit.file_id);
209 for atom in edit.edit.as_atoms() {
210 text_edit_bulder.replace(atom.delete, atom.insert.clone());
211 }
212 }
213 }
214 let result = text_edit_bulder
215 .finish()
216 .apply(&*analysis.file_text(file_id.unwrap()));
217 assert_eq_text!(expected, &*result);
218}
219
220#[test]
221fn world_symbols_include_stuff_from_macros() { 94fn world_symbols_include_stuff_from_macros() {
222 let (analysis, _) = single_file( 95 let (analysis, _) = single_file(
223 " 96 "