diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_analysis/tests/tests.rs | 18 | ||||
-rw-r--r-- | crates/ra_analysis/tests/type_of.rs | 79 |
2 files changed, 80 insertions, 17 deletions
diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs index ce6f6f3fa..3045c2e78 100644 --- a/crates/ra_analysis/tests/tests.rs +++ b/crates/ra_analysis/tests/tests.rs | |||
@@ -2,7 +2,7 @@ use ra_syntax::TextRange; | |||
2 | use test_utils::{assert_eq_dbg, assert_eq_text}; | 2 | use test_utils::{assert_eq_dbg, assert_eq_text}; |
3 | 3 | ||
4 | use ra_analysis::{ | 4 | use ra_analysis::{ |
5 | mock_analysis::{analysis_and_position, analysis_and_range, single_file, single_file_with_position, MockAnalysis}, | 5 | mock_analysis::{analysis_and_position, single_file, single_file_with_position, MockAnalysis}, |
6 | AnalysisChange, CrateGraph, FileId, FnSignatureInfo, | 6 | AnalysisChange, CrateGraph, FileId, FnSignatureInfo, |
7 | }; | 7 | }; |
8 | 8 | ||
@@ -10,22 +10,6 @@ fn get_signature(text: &str) -> (FnSignatureInfo, Option<usize>) { | |||
10 | let (analysis, position) = single_file_with_position(text); | 10 | let (analysis, position) = single_file_with_position(text); |
11 | analysis.resolve_callable(position).unwrap().unwrap() | 11 | analysis.resolve_callable(position).unwrap().unwrap() |
12 | } | 12 | } |
13 | #[test] | ||
14 | fn test_type_of() { | ||
15 | let (analysis, range) = analysis_and_range( | ||
16 | " | ||
17 | //- /lib.rs | ||
18 | pub fn foo() -> u32 { | ||
19 | 1 | ||
20 | }; | ||
21 | |||
22 | let <|>foo_test<|> = foo(); | ||
23 | ", | ||
24 | ); | ||
25 | |||
26 | let type_name = analysis.type_of(range).unwrap().unwrap(); | ||
27 | assert_eq_dbg("u32", &type_name); | ||
28 | } | ||
29 | 13 | ||
30 | #[test] | 14 | #[test] |
31 | fn approximate_resolve_works_in_items() { | 15 | fn approximate_resolve_works_in_items() { |
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 | } | ||