aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/goto_type_definition.rs113
1 files changed, 53 insertions, 60 deletions
diff --git a/crates/ra_ide/src/goto_type_definition.rs b/crates/ra_ide/src/goto_type_definition.rs
index d9cf975d4..723c3e8ae 100644
--- a/crates/ra_ide/src/goto_type_definition.rs
+++ b/crates/ra_ide/src/goto_type_definition.rs
@@ -54,105 +54,98 @@ fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
54 54
55#[cfg(test)] 55#[cfg(test)]
56mod tests { 56mod tests {
57 use crate::mock_analysis::analysis_and_position; 57 use ra_db::FileRange;
58 58
59 fn check_goto(ra_fixture: &str, expected: &str) { 59 use crate::mock_analysis::MockAnalysis;
60 let (analysis, pos) = analysis_and_position(ra_fixture);
61 60
62 let mut navs = analysis.goto_type_definition(pos).unwrap().unwrap().info; 61 fn check(ra_fixture: &str) {
62 let (mock, position) = MockAnalysis::with_files_and_position(ra_fixture);
63 let (expected, data) = mock.annotation();
64 assert!(data.is_empty());
65 let analysis = mock.analysis();
66
67 let mut navs = analysis.goto_type_definition(position).unwrap().unwrap().info;
63 assert_eq!(navs.len(), 1); 68 assert_eq!(navs.len(), 1);
64 let nav = navs.pop().unwrap(); 69 let nav = navs.pop().unwrap();
65 nav.assert_match(expected); 70 assert_eq!(expected, FileRange { file_id: nav.file_id(), range: nav.range() });
66 } 71 }
67 72
68 #[test] 73 #[test]
69 fn goto_type_definition_works_simple() { 74 fn goto_type_definition_works_simple() {
70 check_goto( 75 check(
71 r" 76 r#"
72 //- /lib.rs 77struct Foo;
73 struct Foo; 78 //^^^
74 fn foo() { 79fn foo() {
75 let f: Foo; 80 let f: Foo; f<|>
76 f<|> 81}
77 } 82"#,
78 ",
79 "Foo STRUCT_DEF FileId(1) 0..11 7..10",
80 ); 83 );
81 } 84 }
82 85
83 #[test] 86 #[test]
84 fn goto_type_definition_works_simple_ref() { 87 fn goto_type_definition_works_simple_ref() {
85 check_goto( 88 check(
86 r" 89 r#"
87 //- /lib.rs 90struct Foo;
88 struct Foo; 91 //^^^
89 fn foo() { 92fn foo() {
90 let f: &Foo; 93 let f: &Foo; f<|>
91 f<|> 94}
92 } 95"#,
93 ",
94 "Foo STRUCT_DEF FileId(1) 0..11 7..10",
95 ); 96 );
96 } 97 }
97 98
98 #[test] 99 #[test]
99 fn goto_type_definition_works_through_macro() { 100 fn goto_type_definition_works_through_macro() {
100 check_goto( 101 check(
101 r" 102 r#"
102 //- /lib.rs 103macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
103 macro_rules! id { 104struct Foo {}
104 ($($tt:tt)*) => { $($tt)* } 105 //^^^
105 } 106id! {
106 struct Foo {} 107 fn bar() { let f<|> = Foo {}; }
107 id! { 108}
108 fn bar() { 109"#,
109 let f<|> = Foo {};
110 }
111 }
112 ",
113 "Foo STRUCT_DEF FileId(1) 52..65 59..62",
114 ); 110 );
115 } 111 }
116 112
117 #[test] 113 #[test]
118 fn goto_type_definition_for_param() { 114 fn goto_type_definition_for_param() {
119 check_goto( 115 check(
120 r" 116 r#"
121 //- /lib.rs 117struct Foo;
122 struct Foo; 118 //^^^
123 fn foo(<|>f: Foo) {} 119fn foo(<|>f: Foo) {}
124 ", 120"#,
125 "Foo STRUCT_DEF FileId(1) 0..11 7..10",
126 ); 121 );
127 } 122 }
128 123
129 #[test] 124 #[test]
130 fn goto_type_definition_for_tuple_field() { 125 fn goto_type_definition_for_tuple_field() {
131 check_goto( 126 check(
132 r" 127 r#"
133 //- /lib.rs 128struct Foo;
134 struct Foo; 129 //^^^
135 struct Bar(Foo); 130struct Bar(Foo);
136 fn foo() { 131fn foo() {
137 let bar = Bar(Foo); 132 let bar = Bar(Foo);
138 bar.<|>0; 133 bar.<|>0;
139 } 134}
140 ", 135"#,
141 "Foo STRUCT_DEF FileId(1) 0..11 7..10",
142 ); 136 );
143 } 137 }
144 138
145 #[test] 139 #[test]
146 fn goto_def_for_self_param() { 140 fn goto_def_for_self_param() {
147 check_goto( 141 check(
148 r#" 142 r#"
149struct Foo; 143struct Foo;
144 //^^^
150impl Foo { 145impl Foo {
151 //^^^
152 fn f(&self<|>) {} 146 fn f(&self<|>) {}
153} 147}
154"#, 148"#,
155 "Foo STRUCT_DEF FileId(1) 0..11 7..10",
156 ) 149 )
157 } 150 }
158} 151}