aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis
diff options
context:
space:
mode:
authorHirokazu Hata <[email protected]>2019-01-03 09:48:03 +0000
committerHirokazu Hata <[email protected]>2019-01-03 10:04:42 +0000
commit4363e7b9b2de715b0108b53d40eb33ed2fcc8532 (patch)
tree9c071d46ac14d4fdc8d4a51d465f4b29221e146e /crates/ra_analysis
parentf99e96698c81a731842ef21ae564470a7d391046 (diff)
Deive type_of test from tests
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r--crates/ra_analysis/tests/tests.rs18
-rw-r--r--crates/ra_analysis/tests/type_of.rs79
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;
2use test_utils::{assert_eq_dbg, assert_eq_text}; 2use test_utils::{assert_eq_dbg, assert_eq_text};
3 3
4use ra_analysis::{ 4use 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]
14fn 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]
31fn approximate_resolve_works_in_items() { 15fn 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 @@
1use ra_analysis::{
2 mock_analysis::{single_file_with_range},
3};
4
5#[test]
6fn 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]
23fn 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]
36fn 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]
52fn 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]
67fn 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}