aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/tests')
-rw-r--r--crates/ra_ide_api/tests/test/main.rs127
-rw-r--r--crates/ra_ide_api/tests/test/snapshots/test__rename_mod.snap36
-rw-r--r--crates/ra_ide_api/tests/test/snapshots/test__rename_mod_in_dir.snap36
3 files changed, 0 insertions, 199 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 "
diff --git a/crates/ra_ide_api/tests/test/snapshots/test__rename_mod.snap b/crates/ra_ide_api/tests/test/snapshots/test__rename_mod.snap
deleted file mode 100644
index 54f622b95..000000000
--- a/crates/ra_ide_api/tests/test/snapshots/test__rename_mod.snap
+++ /dev/null
@@ -1,36 +0,0 @@
1Created: 2019-01-16T14:12:39.379431+00:00
2Creator: [email protected]
3Source: crates/ra_ide_api/tests/test/main.rs
4
5Some(
6 SourceChange {
7 label: "rename",
8 source_file_edits: [
9 SourceFileEdit {
10 file_id: FileId(
11 1
12 ),
13 edit: TextEdit {
14 atoms: [
15 AtomTextEdit {
16 delete: [4; 7),
17 insert: "foo2"
18 }
19 ]
20 }
21 }
22 ],
23 file_system_edits: [
24 MoveFile {
25 src: FileId(
26 2
27 ),
28 dst_source_root: SourceRootId(
29 0
30 ),
31 dst_path: "bar/foo2.rs"
32 }
33 ],
34 cursor_position: None
35 }
36)
diff --git a/crates/ra_ide_api/tests/test/snapshots/test__rename_mod_in_dir.snap b/crates/ra_ide_api/tests/test/snapshots/test__rename_mod_in_dir.snap
deleted file mode 100644
index aac30e89f..000000000
--- a/crates/ra_ide_api/tests/test/snapshots/test__rename_mod_in_dir.snap
+++ /dev/null
@@ -1,36 +0,0 @@
1Created: 2019-01-16T14:12:39.379358+00:00
2Creator: [email protected]
3Source: crates/ra_ide_api/tests/test/main.rs
4
5Some(
6 SourceChange {
7 label: "rename",
8 source_file_edits: [
9 SourceFileEdit {
10 file_id: FileId(
11 1
12 ),
13 edit: TextEdit {
14 atoms: [
15 AtomTextEdit {
16 delete: [4; 7),
17 insert: "foo2"
18 }
19 ]
20 }
21 }
22 ],
23 file_system_edits: [
24 MoveFile {
25 src: FileId(
26 2
27 ),
28 dst_source_root: SourceRootId(
29 0
30 ),
31 dst_path: "foo2/mod.rs"
32 }
33 ],
34 cursor_position: None
35 }
36)