diff options
author | Jeremy A. Kolb <[email protected]> | 2018-10-18 18:40:12 +0100 |
---|---|---|
committer | Jeremy A. Kolb <[email protected]> | 2018-10-18 18:40:12 +0100 |
commit | 3746689e9ddea455d10a41d9fc3af33b22a3707d (patch) | |
tree | 04c4e94e40f5496d961ca2f3dc649da1dd84604e /crates/ra_analysis/tests | |
parent | 2a704035f4b36a0db737f59a7c939d17656b516f (diff) |
Implement Find All References for local variables
Diffstat (limited to 'crates/ra_analysis/tests')
-rw-r--r-- | crates/ra_analysis/tests/tests.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs index e0c637d65..0c2c69ea0 100644 --- a/crates/ra_analysis/tests/tests.rs +++ b/crates/ra_analysis/tests/tests.rs | |||
@@ -10,6 +10,8 @@ use std::sync::Arc; | |||
10 | use ra_analysis::{ | 10 | use ra_analysis::{ |
11 | Analysis, AnalysisHost, CrateGraph, CrateId, FileId, FileResolver, FnDescriptor, JobHandle, | 11 | Analysis, AnalysisHost, CrateGraph, CrateId, FileId, FileResolver, FnDescriptor, JobHandle, |
12 | }; | 12 | }; |
13 | use ra_syntax::TextRange; | ||
14 | |||
13 | use relative_path::{RelativePath, RelativePathBuf}; | 15 | use relative_path::{RelativePath, RelativePathBuf}; |
14 | use rustc_hash::FxHashMap; | 16 | use rustc_hash::FxHashMap; |
15 | use test_utils::{assert_eq_dbg, extract_offset}; | 17 | use test_utils::{assert_eq_dbg, extract_offset}; |
@@ -225,3 +227,43 @@ fn bar() { | |||
225 | assert_eq!(desc.ret_type, None); | 227 | assert_eq!(desc.ret_type, None); |
226 | assert_eq!(param, Some(1)); | 228 | assert_eq!(param, Some(1)); |
227 | } | 229 | } |
230 | |||
231 | fn get_all_refs(text: &str) -> Vec<(FileId, TextRange)> { | ||
232 | let (offset, code) = extract_offset(text); | ||
233 | let code = code.as_str(); | ||
234 | |||
235 | let (_handle, token) = JobHandle::new(); | ||
236 | let snap = analysis(&[("/lib.rs", code)]); | ||
237 | |||
238 | snap.find_all_refs(FileId(1), offset, &token) | ||
239 | } | ||
240 | |||
241 | #[test] | ||
242 | fn test_find_all_refs_for_local() { | ||
243 | let code = r#" | ||
244 | fn main() { | ||
245 | let mut i = 1; | ||
246 | let j = 1; | ||
247 | i = i<|> + j; | ||
248 | |||
249 | { | ||
250 | i = 0; | ||
251 | } | ||
252 | |||
253 | i = 5; | ||
254 | }"#; | ||
255 | |||
256 | let refs = get_all_refs(code); | ||
257 | assert_eq!(refs.len(), 5); | ||
258 | } | ||
259 | |||
260 | #[test] | ||
261 | fn test_find_all_refs_for_param_inside() { | ||
262 | let code = r#" | ||
263 | fn foo(i : u32) -> u32 { | ||
264 | i<|> | ||
265 | }"#; | ||
266 | |||
267 | let refs = get_all_refs(code); | ||
268 | assert_eq!(refs.len(), 2); | ||
269 | } \ No newline at end of file | ||