mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Simplify tests
This commit is contained in:
parent
f4147f6a34
commit
cd4502fd47
1 changed files with 53 additions and 60 deletions
|
@ -54,105 +54,98 @@ fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::mock_analysis::analysis_and_position;
|
use ra_db::FileRange;
|
||||||
|
|
||||||
fn check_goto(ra_fixture: &str, expected: &str) {
|
use crate::mock_analysis::MockAnalysis;
|
||||||
let (analysis, pos) = analysis_and_position(ra_fixture);
|
|
||||||
|
|
||||||
let mut navs = analysis.goto_type_definition(pos).unwrap().unwrap().info;
|
fn check(ra_fixture: &str) {
|
||||||
|
let (mock, position) = MockAnalysis::with_files_and_position(ra_fixture);
|
||||||
|
let (expected, data) = mock.annotation();
|
||||||
|
assert!(data.is_empty());
|
||||||
|
let analysis = mock.analysis();
|
||||||
|
|
||||||
|
let mut navs = analysis.goto_type_definition(position).unwrap().unwrap().info;
|
||||||
assert_eq!(navs.len(), 1);
|
assert_eq!(navs.len(), 1);
|
||||||
let nav = navs.pop().unwrap();
|
let nav = navs.pop().unwrap();
|
||||||
nav.assert_match(expected);
|
assert_eq!(expected, FileRange { file_id: nav.file_id(), range: nav.range() });
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn goto_type_definition_works_simple() {
|
fn goto_type_definition_works_simple() {
|
||||||
check_goto(
|
check(
|
||||||
r"
|
r#"
|
||||||
//- /lib.rs
|
struct Foo;
|
||||||
struct Foo;
|
//^^^
|
||||||
fn foo() {
|
fn foo() {
|
||||||
let f: Foo;
|
let f: Foo; f<|>
|
||||||
f<|>
|
}
|
||||||
}
|
"#,
|
||||||
",
|
|
||||||
"Foo STRUCT_DEF FileId(1) 0..11 7..10",
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn goto_type_definition_works_simple_ref() {
|
fn goto_type_definition_works_simple_ref() {
|
||||||
check_goto(
|
check(
|
||||||
r"
|
r#"
|
||||||
//- /lib.rs
|
struct Foo;
|
||||||
struct Foo;
|
//^^^
|
||||||
fn foo() {
|
fn foo() {
|
||||||
let f: &Foo;
|
let f: &Foo; f<|>
|
||||||
f<|>
|
}
|
||||||
}
|
"#,
|
||||||
",
|
|
||||||
"Foo STRUCT_DEF FileId(1) 0..11 7..10",
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn goto_type_definition_works_through_macro() {
|
fn goto_type_definition_works_through_macro() {
|
||||||
check_goto(
|
check(
|
||||||
r"
|
r#"
|
||||||
//- /lib.rs
|
macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
|
||||||
macro_rules! id {
|
struct Foo {}
|
||||||
($($tt:tt)*) => { $($tt)* }
|
//^^^
|
||||||
}
|
id! {
|
||||||
struct Foo {}
|
fn bar() { let f<|> = Foo {}; }
|
||||||
id! {
|
}
|
||||||
fn bar() {
|
"#,
|
||||||
let f<|> = Foo {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
",
|
|
||||||
"Foo STRUCT_DEF FileId(1) 52..65 59..62",
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn goto_type_definition_for_param() {
|
fn goto_type_definition_for_param() {
|
||||||
check_goto(
|
check(
|
||||||
r"
|
r#"
|
||||||
//- /lib.rs
|
struct Foo;
|
||||||
struct Foo;
|
//^^^
|
||||||
fn foo(<|>f: Foo) {}
|
fn foo(<|>f: Foo) {}
|
||||||
",
|
"#,
|
||||||
"Foo STRUCT_DEF FileId(1) 0..11 7..10",
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn goto_type_definition_for_tuple_field() {
|
fn goto_type_definition_for_tuple_field() {
|
||||||
check_goto(
|
check(
|
||||||
r"
|
r#"
|
||||||
//- /lib.rs
|
struct Foo;
|
||||||
struct Foo;
|
//^^^
|
||||||
struct Bar(Foo);
|
struct Bar(Foo);
|
||||||
fn foo() {
|
fn foo() {
|
||||||
let bar = Bar(Foo);
|
let bar = Bar(Foo);
|
||||||
bar.<|>0;
|
bar.<|>0;
|
||||||
}
|
}
|
||||||
",
|
"#,
|
||||||
"Foo STRUCT_DEF FileId(1) 0..11 7..10",
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn goto_def_for_self_param() {
|
fn goto_def_for_self_param() {
|
||||||
check_goto(
|
check(
|
||||||
r#"
|
r#"
|
||||||
struct Foo;
|
struct Foo;
|
||||||
impl Foo {
|
|
||||||
//^^^
|
//^^^
|
||||||
|
impl Foo {
|
||||||
fn f(&self<|>) {}
|
fn f(&self<|>) {}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
"Foo STRUCT_DEF FileId(1) 0..11 7..10",
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue