diff options
-rw-r--r-- | crates/ra_analysis/tests/type_of.rs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/crates/ra_analysis/tests/type_of.rs b/crates/ra_analysis/tests/type_of.rs new file mode 100644 index 000000000..375f808bb --- /dev/null +++ b/crates/ra_analysis/tests/type_of.rs | |||
@@ -0,0 +1,79 @@ | |||
1 | use ra_analysis::{ | ||
2 | mock_analysis::{single_file_with_range}, | ||
3 | }; | ||
4 | |||
5 | #[test] | ||
6 | fn test_type_of_for_function() { | ||
7 | let (analysis, range) = single_file_with_range( | ||
8 | " | ||
9 | pub fn foo() -> u32 { 1 }; | ||
10 | |||
11 | fn main() { | ||
12 | let foo_test = <|>foo()<|>; | ||
13 | } | ||
14 | ", | ||
15 | ); | ||
16 | |||
17 | let type_name = analysis.type_of(range).unwrap().unwrap(); | ||
18 | assert_eq!("u32", &type_name); | ||
19 | } | ||
20 | |||
21 | // FIXME: improve type_of to make this work | ||
22 | #[test] | ||
23 | fn test_type_of_for_num() { | ||
24 | let (analysis, range) = single_file_with_range( | ||
25 | r#" | ||
26 | fn main() { | ||
27 | let foo_test = <|>"foo"<|>; | ||
28 | } | ||
29 | "#, | ||
30 | ); | ||
31 | |||
32 | assert!(analysis.type_of(range).unwrap().is_none()); | ||
33 | } | ||
34 | // FIXME: improve type_of to make this work | ||
35 | #[test] | ||
36 | fn test_type_of_for_binding() { | ||
37 | let (analysis, range) = single_file_with_range( | ||
38 | " | ||
39 | pub fn foo() -> u32 { 1 }; | ||
40 | |||
41 | fn main() { | ||
42 | let <|>foo_test<|> = foo(); | ||
43 | } | ||
44 | ", | ||
45 | ); | ||
46 | |||
47 | assert!(analysis.type_of(range).unwrap().is_none()); | ||
48 | } | ||
49 | |||
50 | // FIXME: improve type_of to make this work | ||
51 | #[test] | ||
52 | fn test_type_of_for_expr_1() { | ||
53 | let (analysis, range) = single_file_with_range( | ||
54 | " | ||
55 | fn main() { | ||
56 | let foo = <|>1 + foo_test<|>; | ||
57 | } | ||
58 | ", | ||
59 | ); | ||
60 | |||
61 | let type_name = analysis.type_of(range).unwrap().unwrap(); | ||
62 | assert_eq!("[unknown]", &type_name); | ||
63 | } | ||
64 | |||
65 | // FIXME: improve type_of to make this work | ||
66 | #[test] | ||
67 | fn test_type_of_for_expr_2() { | ||
68 | let (analysis, range) = single_file_with_range( | ||
69 | " | ||
70 | fn main() { | ||
71 | let foo: usize = 1; | ||
72 | let bar = <|>1 + foo_test<|>; | ||
73 | } | ||
74 | ", | ||
75 | ); | ||
76 | |||
77 | let type_name = analysis.type_of(range).unwrap().unwrap(); | ||
78 | assert_eq!("[unknown]", &type_name); | ||
79 | } | ||