diff options
Diffstat (limited to 'crates/ra_ide/src/goto_definition.rs')
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 27052d72b..bee8e9df2 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs | |||
@@ -221,7 +221,7 @@ fn named_target(db: &RootDatabase, node: InFile<&SyntaxNode>) -> Option<Navigati | |||
221 | 221 | ||
222 | #[cfg(test)] | 222 | #[cfg(test)] |
223 | mod tests { | 223 | mod tests { |
224 | use test_utils::covers; | 224 | use test_utils::{assert_eq_text, covers}; |
225 | 225 | ||
226 | use crate::mock_analysis::analysis_and_position; | 226 | use crate::mock_analysis::analysis_and_position; |
227 | 227 | ||
@@ -234,6 +234,24 @@ mod tests { | |||
234 | nav.assert_match(expected); | 234 | nav.assert_match(expected); |
235 | } | 235 | } |
236 | 236 | ||
237 | fn check_goto_with_range_content(fixture: &str, expected: &str, expected_range: &str) { | ||
238 | let (analysis, pos) = analysis_and_position(fixture); | ||
239 | |||
240 | let mut navs = analysis.goto_definition(pos).unwrap().unwrap().info; | ||
241 | assert_eq!(navs.len(), 1); | ||
242 | let nav = navs.pop().unwrap(); | ||
243 | let file_text = analysis.file_text(pos.file_id).unwrap(); | ||
244 | |||
245 | let actual_full_range = &file_text[nav.full_range()]; | ||
246 | let actual_range = &file_text[nav.range()]; | ||
247 | |||
248 | test_utils::assert_eq_text!( | ||
249 | &format!("{}|{}", actual_full_range, actual_range), | ||
250 | expected_range | ||
251 | ); | ||
252 | nav.assert_match(expected); | ||
253 | } | ||
254 | |||
237 | #[test] | 255 | #[test] |
238 | fn goto_definition_works_in_items() { | 256 | fn goto_definition_works_in_items() { |
239 | check_goto( | 257 | check_goto( |
@@ -363,28 +381,27 @@ mod tests { | |||
363 | 381 | ||
364 | #[test] | 382 | #[test] |
365 | fn goto_definition_works_for_macro_defined_fn_with_arg() { | 383 | fn goto_definition_works_for_macro_defined_fn_with_arg() { |
366 | check_goto( | 384 | check_goto_with_range_content( |
367 | " | 385 | " |
368 | //- /lib.rs | 386 | //- /lib.rs |
369 | macro_rules! define_fn { | 387 | macro_rules! define_fn { |
370 | ($name:ident) => (fn $name() {}) | 388 | ($name:ident) => (fn $name() {}) |
371 | } | 389 | } |
372 | 390 | ||
373 | define_fn!( | 391 | define_fn!(foo); |
374 | foo | ||
375 | ) | ||
376 | 392 | ||
377 | fn bar() { | 393 | fn bar() { |
378 | <|>foo(); | 394 | <|>foo(); |
379 | } | 395 | } |
380 | ", | 396 | ", |
381 | "foo FN_DEF FileId(1) [80; 83) [80; 83)", | 397 | "foo FN_DEF FileId(1) [64; 80) [75; 78)", |
398 | "define_fn!(foo);|foo", | ||
382 | ); | 399 | ); |
383 | } | 400 | } |
384 | 401 | ||
385 | #[test] | 402 | #[test] |
386 | fn goto_definition_works_for_macro_defined_fn_no_arg() { | 403 | fn goto_definition_works_for_macro_defined_fn_no_arg() { |
387 | check_goto( | 404 | check_goto_with_range_content( |
388 | " | 405 | " |
389 | //- /lib.rs | 406 | //- /lib.rs |
390 | macro_rules! define_fn { | 407 | macro_rules! define_fn { |
@@ -397,7 +414,8 @@ mod tests { | |||
397 | <|>foo(); | 414 | <|>foo(); |
398 | } | 415 | } |
399 | ", | 416 | ", |
400 | "foo FN_DEF FileId(1) [39; 42) [39; 42)", | 417 | "foo FN_DEF FileId(1) [51; 64) [51; 64)", |
418 | "define_fn!();|define_fn!();", | ||
401 | ); | 419 | ); |
402 | } | 420 | } |
403 | 421 | ||