aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r--crates/ra_hir/src/ty/tests.rs39
1 files changed, 28 insertions, 11 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 25a354947..83aedaa00 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -5,7 +5,7 @@ use std::fs;
5 5
6use salsa::Database; 6use salsa::Database;
7 7
8use ra_db::{SyntaxDatabase}; 8use ra_db::SyntaxDatabase;
9use ra_syntax::ast::{self, AstNode}; 9use ra_syntax::ast::{self, AstNode};
10use test_utils::{project_dir, assert_eq_text, read_text}; 10use test_utils::{project_dir, assert_eq_text, read_text};
11 11
@@ -34,7 +34,7 @@ fn test(a: u32, b: isize, c: !, d: &str) {
34 "test"; 34 "test";
35 1.0f32; 35 1.0f32;
36}"#, 36}"#,
37 "0001_basics.txt", 37 "basics.txt",
38 ); 38 );
39} 39}
40 40
@@ -48,7 +48,7 @@ fn test() {
48 let c = b; 48 let c = b;
49} 49}
50}"#, 50}"#,
51 "0002_let.txt", 51 "let.txt",
52 ); 52 );
53} 53}
54 54
@@ -67,7 +67,7 @@ fn test() {
67 b::c(); 67 b::c();
68} 68}
69}"#, 69}"#,
70 "0003_paths.txt", 70 "paths.txt",
71 ); 71 );
72} 72}
73 73
@@ -90,7 +90,7 @@ fn test() {
90 a.c; 90 a.c;
91} 91}
92"#, 92"#,
93 "0004_struct.txt", 93 "struct.txt",
94 ); 94 );
95} 95}
96 96
@@ -112,7 +112,7 @@ fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
112 *d; 112 *d;
113} 113}
114"#, 114"#,
115 "0005_refs.txt", 115 "refs_and_ptrs.txt",
116 ); 116 );
117} 117}
118 118
@@ -133,7 +133,7 @@ fn test() -> &mut &f64 {
133 &mut &c 133 &mut &c
134} 134}
135"#, 135"#,
136 "0006_backwards.txt", 136 "backwards.txt",
137 ); 137 );
138} 138}
139 139
@@ -152,7 +152,7 @@ impl S {
152 } 152 }
153} 153}
154"#, 154"#,
155 "0007_self.txt", 155 "self.txt",
156 ); 156 );
157} 157}
158 158
@@ -176,7 +176,7 @@ fn test() {
176 10 < 3 176 10 < 3
177} 177}
178"#, 178"#,
179 "0008_boolean_op.txt", 179 "boolean_op.txt",
180 ); 180 );
181} 181}
182 182
@@ -193,7 +193,25 @@ fn infer(content: &str) -> String {
193 .unwrap() 193 .unwrap()
194 .unwrap(); 194 .unwrap();
195 let inference_result = func.infer(&db).unwrap(); 195 let inference_result = func.infer(&db).unwrap();
196 for (syntax_ptr, ty) in &inference_result.type_of { 196 let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap();
197 let mut types = Vec::new();
198 for (pat, ty) in inference_result.type_of_pat.iter() {
199 let syntax_ptr = match body_syntax_mapping.pat_syntax(pat) {
200 Some(sp) => sp,
201 None => continue,
202 };
203 types.push((syntax_ptr, ty));
204 }
205 for (expr, ty) in inference_result.type_of_expr.iter() {
206 let syntax_ptr = match body_syntax_mapping.expr_syntax(expr) {
207 Some(sp) => sp,
208 None => continue,
209 };
210 types.push((syntax_ptr, ty));
211 }
212 // sort ranges for consistency
213 types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end()));
214 for (syntax_ptr, ty) in &types {
197 let node = syntax_ptr.resolve(&source_file); 215 let node = syntax_ptr.resolve(&source_file);
198 write!( 216 write!(
199 acc, 217 acc,
@@ -246,7 +264,6 @@ fn test_data_dir() -> PathBuf {
246} 264}
247 265
248#[test] 266#[test]
249#[should_panic] // TODO this should work once hir::Expr is used
250fn typing_whitespace_inside_a_function_should_not_invalidate_types() { 267fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
251 let (mut db, pos) = MockDatabase::with_position( 268 let (mut db, pos) = MockDatabase::with_position(
252 " 269 "