diff options
Diffstat (limited to 'crates/ra_ide_api/src/references.rs')
-rw-r--r-- | crates/ra_ide_api/src/references.rs | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs index 22741445a..20bbf11a3 100644 --- a/crates/ra_ide_api/src/references.rs +++ b/crates/ra_ide_api/src/references.rs | |||
@@ -216,10 +216,56 @@ mod tests { | |||
216 | use crate::{ | 216 | use crate::{ |
217 | mock_analysis::single_file_with_position, | 217 | mock_analysis::single_file_with_position, |
218 | mock_analysis::analysis_and_position, | 218 | mock_analysis::analysis_and_position, |
219 | FileId | 219 | FileId, ReferenceSearchResult |
220 | }; | 220 | }; |
221 | 221 | ||
222 | #[test] | 222 | #[test] |
223 | fn test_find_all_refs_for_local() { | ||
224 | let code = r#" | ||
225 | fn main() { | ||
226 | let mut i = 1; | ||
227 | let j = 1; | ||
228 | i = i<|> + j; | ||
229 | |||
230 | { | ||
231 | i = 0; | ||
232 | } | ||
233 | |||
234 | i = 5; | ||
235 | }"#; | ||
236 | |||
237 | let refs = get_all_refs(code); | ||
238 | assert_eq!(refs.len(), 5); | ||
239 | } | ||
240 | |||
241 | #[test] | ||
242 | fn test_find_all_refs_for_param_inside() { | ||
243 | let code = r#" | ||
244 | fn foo(i : u32) -> u32 { | ||
245 | i<|> | ||
246 | }"#; | ||
247 | |||
248 | let refs = get_all_refs(code); | ||
249 | assert_eq!(refs.len(), 2); | ||
250 | } | ||
251 | |||
252 | #[test] | ||
253 | fn test_find_all_refs_for_fn_param() { | ||
254 | let code = r#" | ||
255 | fn foo(i<|> : u32) -> u32 { | ||
256 | i | ||
257 | }"#; | ||
258 | |||
259 | let refs = get_all_refs(code); | ||
260 | assert_eq!(refs.len(), 2); | ||
261 | } | ||
262 | |||
263 | fn get_all_refs(text: &str) -> ReferenceSearchResult { | ||
264 | let (analysis, position) = single_file_with_position(text); | ||
265 | analysis.find_all_refs(position).unwrap().unwrap() | ||
266 | } | ||
267 | |||
268 | #[test] | ||
223 | fn test_rename_for_local() { | 269 | fn test_rename_for_local() { |
224 | test_rename( | 270 | test_rename( |
225 | r#" | 271 | r#" |