Add example expect test for goto definition

This commit is contained in:
Aleksey Kladov 2020-06-27 18:21:26 +02:00
parent 03c5a6690d
commit be265ece02
3 changed files with 35 additions and 8 deletions

1
Cargo.lock generated
View file

@ -1130,6 +1130,7 @@ name = "ra_ide"
version = "0.1.0"
dependencies = [
"either",
"expect",
"indexmap",
"insta",
"itertools",

View file

@ -28,6 +28,7 @@ ra_cfg = { path = "../ra_cfg" }
ra_fmt = { path = "../ra_fmt" }
ra_prof = { path = "../ra_prof" }
test_utils = { path = "../test_utils" }
expect = { path = "../expect" }
ra_assists = { path = "../ra_assists" }
ra_ssr = { path = "../ra_ssr" }

View file

@ -103,6 +103,7 @@ pub(crate) fn reference_definition(
#[cfg(test)]
mod tests {
use expect::{expect, Expect};
use test_utils::assert_eq_text;
use crate::mock_analysis::analysis_and_position;
@ -142,16 +143,40 @@ mod tests {
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]
fn goto_def_in_items() {
check_goto(
"
//- /lib.rs
check(
r#"
struct Foo;
enum E { X(Foo<|>) }
",
"Foo STRUCT_DEF FileId(1) 0..11 7..10",
"struct Foo;|Foo",
"#,
expect![[r#"
Foo STRUCT_DEF FileId(1) 0..11 7..10
struct Foo;|Foo
"#]],
);
}