mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Add example expect test for goto definition
This commit is contained in:
parent
03c5a6690d
commit
be265ece02
3 changed files with 35 additions and 8 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1130,6 +1130,7 @@ name = "ra_ide"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"either",
|
"either",
|
||||||
|
"expect",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"insta",
|
"insta",
|
||||||
"itertools",
|
"itertools",
|
||||||
|
|
|
@ -28,6 +28,7 @@ ra_cfg = { path = "../ra_cfg" }
|
||||||
ra_fmt = { path = "../ra_fmt" }
|
ra_fmt = { path = "../ra_fmt" }
|
||||||
ra_prof = { path = "../ra_prof" }
|
ra_prof = { path = "../ra_prof" }
|
||||||
test_utils = { path = "../test_utils" }
|
test_utils = { path = "../test_utils" }
|
||||||
|
expect = { path = "../expect" }
|
||||||
ra_assists = { path = "../ra_assists" }
|
ra_assists = { path = "../ra_assists" }
|
||||||
ra_ssr = { path = "../ra_ssr" }
|
ra_ssr = { path = "../ra_ssr" }
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,7 @@ pub(crate) fn reference_definition(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use expect::{expect, Expect};
|
||||||
use test_utils::assert_eq_text;
|
use test_utils::assert_eq_text;
|
||||||
|
|
||||||
use crate::mock_analysis::analysis_and_position;
|
use crate::mock_analysis::analysis_and_position;
|
||||||
|
@ -142,16 +143,40 @@ mod tests {
|
||||||
nav.assert_match(expected);
|
nav.assert_match(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
|
let (analysis, pos) = analysis_and_position(ra_fixture);
|
||||||
|
|
||||||
|
let mut navs = analysis.goto_definition(pos).unwrap().unwrap().info;
|
||||||
|
if navs.len() == 0 {
|
||||||
|
panic!("unresolved reference")
|
||||||
|
}
|
||||||
|
assert_eq!(navs.len(), 1);
|
||||||
|
|
||||||
|
let nav = navs.pop().unwrap();
|
||||||
|
let file_text = analysis.file_text(nav.file_id()).unwrap();
|
||||||
|
|
||||||
|
let mut actual = nav.debug_render();
|
||||||
|
actual += "\n";
|
||||||
|
actual += &file_text[nav.full_range()].to_string();
|
||||||
|
if let Some(focus) = nav.focus_range() {
|
||||||
|
actual += "|";
|
||||||
|
actual += &file_text[focus];
|
||||||
|
actual += "\n";
|
||||||
|
}
|
||||||
|
expect.assert_eq(&actual);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn goto_def_in_items() {
|
fn goto_def_in_items() {
|
||||||
check_goto(
|
check(
|
||||||
"
|
r#"
|
||||||
//- /lib.rs
|
struct Foo;
|
||||||
struct Foo;
|
enum E { X(Foo<|>) }
|
||||||
enum E { X(Foo<|>) }
|
"#,
|
||||||
",
|
expect![[r#"
|
||||||
"Foo STRUCT_DEF FileId(1) 0..11 7..10",
|
Foo STRUCT_DEF FileId(1) 0..11 7..10
|
||||||
"struct Foo;|Foo",
|
struct Foo;|Foo
|
||||||
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue