diff options
author | gfreezy <[email protected]> | 2019-01-18 08:29:09 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-19 12:36:58 +0000 |
commit | 360167db16a3ae6bb3146cf8e05336288b711921 (patch) | |
tree | 7ebb001ab92b37b05aa0c62208ee6915bffec097 /crates/ra_ide_api/tests | |
parent | 6ab6d1eaa036f8620542ad9c12764957e868b7e0 (diff) |
prefer inline tests
Diffstat (limited to 'crates/ra_ide_api/tests')
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 | }; |
5 | use ra_ide_api::mock_analysis::analysis_and_position; | ||
6 | use ra_syntax::TextRange; | 5 | use ra_syntax::TextRange; |
7 | use test_utils::assert_eq_text; | ||
8 | use insta::assert_debug_snapshot_matches; | 6 | use 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] |
96 | fn 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] | ||
127 | fn 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] | ||
142 | fn 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] | ||
157 | fn 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] | ||
172 | fn 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] | ||
187 | fn 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 | |||
201 | fn 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] | ||
221 | fn world_symbols_include_stuff_from_macros() { | 94 | fn 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 @@ | |||
1 | Created: 2019-01-16T14:12:39.379431+00:00 | ||
2 | Creator: [email protected] | ||
3 | Source: crates/ra_ide_api/tests/test/main.rs | ||
4 | |||
5 | Some( | ||
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 @@ | |||
1 | Created: 2019-01-16T14:12:39.379358+00:00 | ||
2 | Creator: [email protected] | ||
3 | Source: crates/ra_ide_api/tests/test/main.rs | ||
4 | |||
5 | Some( | ||
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 | ) | ||