diff options
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/hover.rs | 50 | ||||
-rw-r--r-- | crates/ra_analysis/tests/test/main.rs | 1 | ||||
-rw-r--r-- | crates/ra_analysis/tests/test/type_of.rs | 77 |
3 files changed, 49 insertions, 79 deletions
diff --git a/crates/ra_analysis/src/hover.rs b/crates/ra_analysis/src/hover.rs index 8217df305..2cf79eebf 100644 --- a/crates/ra_analysis/src/hover.rs +++ b/crates/ra_analysis/src/hover.rs | |||
@@ -167,7 +167,7 @@ impl NavigationTarget { | |||
167 | #[cfg(test)] | 167 | #[cfg(test)] |
168 | mod tests { | 168 | mod tests { |
169 | use ra_syntax::TextRange; | 169 | use ra_syntax::TextRange; |
170 | use crate::mock_analysis::single_file_with_position; | 170 | use crate::mock_analysis::{single_file_with_position, single_file_with_range}; |
171 | 171 | ||
172 | #[test] | 172 | #[test] |
173 | fn hover_shows_type_of_an_expression() { | 173 | fn hover_shows_type_of_an_expression() { |
@@ -191,4 +191,52 @@ mod tests { | |||
191 | let hover = analysis.hover(position).unwrap().unwrap(); | 191 | let hover = analysis.hover(position).unwrap().unwrap(); |
192 | assert_eq!(hover.info, "i32"); | 192 | assert_eq!(hover.info, "i32"); |
193 | } | 193 | } |
194 | |||
195 | #[test] | ||
196 | fn test_type_of_for_function() { | ||
197 | let (analysis, range) = single_file_with_range( | ||
198 | " | ||
199 | pub fn foo() -> u32 { 1 }; | ||
200 | |||
201 | fn main() { | ||
202 | let foo_test = <|>foo()<|>; | ||
203 | } | ||
204 | ", | ||
205 | ); | ||
206 | |||
207 | let type_name = analysis.type_of(range).unwrap().unwrap(); | ||
208 | assert_eq!("u32", &type_name); | ||
209 | } | ||
210 | |||
211 | // FIXME: improve type_of to make this work | ||
212 | #[test] | ||
213 | fn test_type_of_for_expr_1() { | ||
214 | let (analysis, range) = single_file_with_range( | ||
215 | " | ||
216 | fn main() { | ||
217 | let foo = <|>1 + foo_test<|>; | ||
218 | } | ||
219 | ", | ||
220 | ); | ||
221 | |||
222 | let type_name = analysis.type_of(range).unwrap().unwrap(); | ||
223 | assert_eq!("[unknown]", &type_name); | ||
224 | } | ||
225 | |||
226 | // FIXME: improve type_of to make this work | ||
227 | #[test] | ||
228 | fn test_type_of_for_expr_2() { | ||
229 | let (analysis, range) = single_file_with_range( | ||
230 | " | ||
231 | fn main() { | ||
232 | let foo: usize = 1; | ||
233 | let bar = <|>1 + foo_test<|>; | ||
234 | } | ||
235 | ", | ||
236 | ); | ||
237 | |||
238 | let type_name = analysis.type_of(range).unwrap().unwrap(); | ||
239 | assert_eq!("[unknown]", &type_name); | ||
240 | } | ||
241 | |||
194 | } | 242 | } |
diff --git a/crates/ra_analysis/tests/test/main.rs b/crates/ra_analysis/tests/test/main.rs index e15035304..26da7c10c 100644 --- a/crates/ra_analysis/tests/test/main.rs +++ b/crates/ra_analysis/tests/test/main.rs | |||
@@ -1,5 +1,4 @@ | |||
1 | mod runnables; | 1 | mod runnables; |
2 | mod type_of; | ||
3 | 2 | ||
4 | use ra_syntax::TextRange; | 3 | use ra_syntax::TextRange; |
5 | use test_utils::{assert_eq_dbg, assert_eq_text}; | 4 | use test_utils::{assert_eq_dbg, assert_eq_text}; |
diff --git a/crates/ra_analysis/tests/test/type_of.rs b/crates/ra_analysis/tests/test/type_of.rs deleted file mode 100644 index 9d15b52a8..000000000 --- a/crates/ra_analysis/tests/test/type_of.rs +++ /dev/null | |||
@@ -1,77 +0,0 @@ | |||
1 | use ra_analysis::mock_analysis::single_file_with_range; | ||
2 | |||
3 | #[test] | ||
4 | fn test_type_of_for_function() { | ||
5 | let (analysis, range) = single_file_with_range( | ||
6 | " | ||
7 | pub fn foo() -> u32 { 1 }; | ||
8 | |||
9 | fn main() { | ||
10 | let foo_test = <|>foo()<|>; | ||
11 | } | ||
12 | ", | ||
13 | ); | ||
14 | |||
15 | let type_name = analysis.type_of(range).unwrap().unwrap(); | ||
16 | assert_eq!("u32", &type_name); | ||
17 | } | ||
18 | |||
19 | // FIXME: improve type_of to make this work | ||
20 | #[test] | ||
21 | fn test_type_of_for_num() { | ||
22 | let (analysis, range) = single_file_with_range( | ||
23 | r#" | ||
24 | fn main() { | ||
25 | let foo_test = <|>"foo"<|>; | ||
26 | } | ||
27 | "#, | ||
28 | ); | ||
29 | |||
30 | assert!(analysis.type_of(range).unwrap().is_none()); | ||
31 | } | ||
32 | // FIXME: improve type_of to make this work | ||
33 | #[test] | ||
34 | fn test_type_of_for_binding() { | ||
35 | let (analysis, range) = single_file_with_range( | ||
36 | " | ||
37 | pub fn foo() -> u32 { 1 }; | ||
38 | |||
39 | fn main() { | ||
40 | let <|>foo_test<|> = foo(); | ||
41 | } | ||
42 | ", | ||
43 | ); | ||
44 | |||
45 | assert!(analysis.type_of(range).unwrap().is_none()); | ||
46 | } | ||
47 | |||
48 | // FIXME: improve type_of to make this work | ||
49 | #[test] | ||
50 | fn test_type_of_for_expr_1() { | ||
51 | let (analysis, range) = single_file_with_range( | ||
52 | " | ||
53 | fn main() { | ||
54 | let foo = <|>1 + foo_test<|>; | ||
55 | } | ||
56 | ", | ||
57 | ); | ||
58 | |||
59 | let type_name = analysis.type_of(range).unwrap().unwrap(); | ||
60 | assert_eq!("[unknown]", &type_name); | ||
61 | } | ||
62 | |||
63 | // FIXME: improve type_of to make this work | ||
64 | #[test] | ||
65 | fn test_type_of_for_expr_2() { | ||
66 | let (analysis, range) = single_file_with_range( | ||
67 | " | ||
68 | fn main() { | ||
69 | let foo: usize = 1; | ||
70 | let bar = <|>1 + foo_test<|>; | ||
71 | } | ||
72 | ", | ||
73 | ); | ||
74 | |||
75 | let type_name = analysis.type_of(range).unwrap().unwrap(); | ||
76 | assert_eq!("[unknown]", &type_name); | ||
77 | } | ||