diff options
author | Florian Diebold <[email protected]> | 2019-01-06 22:01:33 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-01-06 23:05:19 +0000 |
commit | cf49a11263c4d48720250db0c448b97dbec3d8b9 (patch) | |
tree | 7636e9919e5390b7b6d01d92aaf5336a3fbe590b /crates/ra_hir/src/ty/tests.rs | |
parent | 6210e82041849bad6129331b9e45ac0bae6fe569 (diff) |
Sort ranges in type inference tests
Also rename the files to remove the numbers (they don't serve a purpose now that
there are only the data files).
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index e46f309ae..20fb783b8 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -4,7 +4,6 @@ use std::path::{PathBuf, Path}; | |||
4 | use std::fs; | 4 | use std::fs; |
5 | 5 | ||
6 | use salsa::Database; | 6 | use salsa::Database; |
7 | use rustc_hash::FxHashMap; | ||
8 | 7 | ||
9 | use ra_db::SyntaxDatabase; | 8 | use ra_db::SyntaxDatabase; |
10 | use ra_syntax::ast::{self, AstNode}; | 9 | use ra_syntax::ast::{self, AstNode}; |
@@ -35,7 +34,7 @@ fn test(a: u32, b: isize, c: !, d: &str) { | |||
35 | "test"; | 34 | "test"; |
36 | 1.0f32; | 35 | 1.0f32; |
37 | }"#, | 36 | }"#, |
38 | "0001_basics.txt", | 37 | "basics.txt", |
39 | ); | 38 | ); |
40 | } | 39 | } |
41 | 40 | ||
@@ -49,7 +48,7 @@ fn test() { | |||
49 | let c = b; | 48 | let c = b; |
50 | } | 49 | } |
51 | }"#, | 50 | }"#, |
52 | "0002_let.txt", | 51 | "let.txt", |
53 | ); | 52 | ); |
54 | } | 53 | } |
55 | 54 | ||
@@ -68,7 +67,7 @@ fn test() { | |||
68 | b::c(); | 67 | b::c(); |
69 | } | 68 | } |
70 | }"#, | 69 | }"#, |
71 | "0003_paths.txt", | 70 | "paths.txt", |
72 | ); | 71 | ); |
73 | } | 72 | } |
74 | 73 | ||
@@ -91,7 +90,7 @@ fn test() { | |||
91 | a.c; | 90 | a.c; |
92 | } | 91 | } |
93 | "#, | 92 | "#, |
94 | "0004_struct.txt", | 93 | "struct.txt", |
95 | ); | 94 | ); |
96 | } | 95 | } |
97 | 96 | ||
@@ -113,7 +112,7 @@ fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) { | |||
113 | *d; | 112 | *d; |
114 | } | 113 | } |
115 | "#, | 114 | "#, |
116 | "0005_refs.txt", | 115 | "refs_and_ptrs.txt", |
117 | ); | 116 | ); |
118 | } | 117 | } |
119 | 118 | ||
@@ -134,7 +133,7 @@ fn test() -> &mut &f64 { | |||
134 | &mut &c | 133 | &mut &c |
135 | } | 134 | } |
136 | "#, | 135 | "#, |
137 | "0006_backwards.txt", | 136 | "backwards.txt", |
138 | ); | 137 | ); |
139 | } | 138 | } |
140 | 139 | ||
@@ -153,7 +152,7 @@ impl S { | |||
153 | } | 152 | } |
154 | } | 153 | } |
155 | "#, | 154 | "#, |
156 | "0007_self.txt", | 155 | "self.txt", |
157 | ); | 156 | ); |
158 | } | 157 | } |
159 | 158 | ||
@@ -177,7 +176,7 @@ fn test() { | |||
177 | 10 < 3 | 176 | 10 < 3 |
178 | } | 177 | } |
179 | "#, | 178 | "#, |
180 | "0008_boolean_op.txt", | 179 | "boolean_op.txt", |
181 | ); | 180 | ); |
182 | } | 181 | } |
183 | 182 | ||
@@ -195,14 +194,14 @@ fn infer(content: &str) -> String { | |||
195 | .unwrap(); | 194 | .unwrap(); |
196 | let inference_result = func.infer(&db).unwrap(); | 195 | let inference_result = func.infer(&db).unwrap(); |
197 | let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap(); | 196 | let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap(); |
198 | let mut types = FxHashMap::default(); | 197 | let mut types = Vec::new(); |
199 | for (pat, ty) in &inference_result.type_of_pat { | 198 | for (pat, ty) in &inference_result.type_of_pat { |
200 | let syntax_ptr = if let Some(sp) = body_syntax_mapping.pat_syntax(*pat) { | 199 | let syntax_ptr = if let Some(sp) = body_syntax_mapping.pat_syntax(*pat) { |
201 | sp | 200 | sp |
202 | } else { | 201 | } else { |
203 | continue; | 202 | continue; |
204 | }; | 203 | }; |
205 | types.insert(syntax_ptr, ty); | 204 | types.push((syntax_ptr, ty)); |
206 | } | 205 | } |
207 | for (expr, ty) in &inference_result.type_of_expr { | 206 | for (expr, ty) in &inference_result.type_of_expr { |
208 | let syntax_ptr = if let Some(sp) = body_syntax_mapping.expr_syntax(*expr) { | 207 | let syntax_ptr = if let Some(sp) = body_syntax_mapping.expr_syntax(*expr) { |
@@ -210,8 +209,10 @@ fn infer(content: &str) -> String { | |||
210 | } else { | 209 | } else { |
211 | continue; | 210 | continue; |
212 | }; | 211 | }; |
213 | types.insert(syntax_ptr, ty); | 212 | types.push((syntax_ptr, ty)); |
214 | } | 213 | } |
214 | // sort ranges for consistency | ||
215 | types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end())); | ||
215 | for (syntax_ptr, ty) in &types { | 216 | for (syntax_ptr, ty) in &types { |
216 | let node = syntax_ptr.resolve(&source_file); | 217 | let node = syntax_ptr.resolve(&source_file); |
217 | write!( | 218 | write!( |