diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-16 14:44:24 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-16 14:44:24 +0100 |
commit | 1216878f7be20dd0e652fb8cdc395009fdcfae07 (patch) | |
tree | 6551967cc8c6e921b66071453ad7888a9121d326 /crates/ra_analysis/tests | |
parent | 39cb6c6d3f78b193f5873c3492e530bbd24d5dd2 (diff) | |
parent | 61f3a438d3a729a6be941bca1ff4c6a97a33f221 (diff) |
Merge #134
134: Cargo Format run r=kjeremy a=kjeremy
I'm not sure how appreciated this is but I figured I would run `cargo fmt` and see what came up.
I made sure that `cargo test` still passes.
Co-authored-by: Jeremy A. Kolb <[email protected]>
Diffstat (limited to 'crates/ra_analysis/tests')
-rw-r--r-- | crates/ra_analysis/tests/tests.rs | 82 |
1 files changed, 34 insertions, 48 deletions
diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs index 2d3679fa9..e0c637d65 100644 --- a/crates/ra_analysis/tests/tests.rs +++ b/crates/ra_analysis/tests/tests.rs | |||
@@ -1,32 +1,31 @@ | |||
1 | extern crate relative_path; | ||
2 | extern crate ra_analysis; | 1 | extern crate ra_analysis; |
3 | extern crate rustc_hash; | ||
4 | extern crate ra_editor; | 2 | extern crate ra_editor; |
5 | extern crate ra_syntax; | 3 | extern crate ra_syntax; |
4 | extern crate relative_path; | ||
5 | extern crate rustc_hash; | ||
6 | extern crate test_utils; | 6 | extern crate test_utils; |
7 | 7 | ||
8 | use std::{ | 8 | use std::sync::Arc; |
9 | sync::Arc, | ||
10 | }; | ||
11 | 9 | ||
12 | use rustc_hash::FxHashMap; | 10 | use ra_analysis::{ |
11 | Analysis, AnalysisHost, CrateGraph, CrateId, FileId, FileResolver, FnDescriptor, JobHandle, | ||
12 | }; | ||
13 | use relative_path::{RelativePath, RelativePathBuf}; | 13 | use relative_path::{RelativePath, RelativePathBuf}; |
14 | use ra_analysis::{Analysis, AnalysisHost, FileId, FileResolver, JobHandle, CrateGraph, CrateId, FnDescriptor}; | 14 | use rustc_hash::FxHashMap; |
15 | use test_utils::{assert_eq_dbg, extract_offset}; | 15 | use test_utils::{assert_eq_dbg, extract_offset}; |
16 | 16 | ||
17 | #[derive(Debug)] | 17 | #[derive(Debug)] |
18 | struct FileMap(Vec<(FileId, RelativePathBuf)>); | 18 | struct FileMap(Vec<(FileId, RelativePathBuf)>); |
19 | 19 | ||
20 | impl FileMap { | 20 | impl FileMap { |
21 | fn iter<'a>(&'a self) -> impl Iterator<Item=(FileId, &'a RelativePath)> + 'a { | 21 | fn iter<'a>(&'a self) -> impl Iterator<Item = (FileId, &'a RelativePath)> + 'a { |
22 | self.0.iter().map(|(id, path)| (*id, path.as_relative_path())) | 22 | self.0 |
23 | .iter() | ||
24 | .map(|(id, path)| (*id, path.as_relative_path())) | ||
23 | } | 25 | } |
24 | 26 | ||
25 | fn path(&self, id: FileId) -> &RelativePath { | 27 | fn path(&self, id: FileId) -> &RelativePath { |
26 | self.iter() | 28 | self.iter().find(|&(it, _)| it == id).unwrap().1 |
27 | .find(|&(it, _)| it == id) | ||
28 | .unwrap() | ||
29 | .1 | ||
30 | } | 29 | } |
31 | } | 30 | } |
32 | 31 | ||
@@ -71,10 +70,7 @@ fn get_signature(text: &str) -> (FnDescriptor, Option<usize>) { | |||
71 | 70 | ||
72 | #[test] | 71 | #[test] |
73 | fn test_resolve_module() { | 72 | fn test_resolve_module() { |
74 | let snap = analysis(&[ | 73 | let snap = analysis(&[("/lib.rs", "mod foo;"), ("/foo.rs", "")]); |
75 | ("/lib.rs", "mod foo;"), | ||
76 | ("/foo.rs", "") | ||
77 | ]); | ||
78 | let (_handle, token) = JobHandle::new(); | 74 | let (_handle, token) = JobHandle::new(); |
79 | let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into(), &token); | 75 | let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into(), &token); |
80 | assert_eq_dbg( | 76 | assert_eq_dbg( |
@@ -82,10 +78,7 @@ fn test_resolve_module() { | |||
82 | &symbols, | 78 | &symbols, |
83 | ); | 79 | ); |
84 | 80 | ||
85 | let snap = analysis(&[ | 81 | let snap = analysis(&[("/lib.rs", "mod foo;"), ("/foo/mod.rs", "")]); |
86 | ("/lib.rs", "mod foo;"), | ||
87 | ("/foo/mod.rs", "") | ||
88 | ]); | ||
89 | let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into(), &token); | 82 | let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into(), &token); |
90 | assert_eq_dbg( | 83 | assert_eq_dbg( |
91 | r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#, | 84 | r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#, |
@@ -114,18 +107,12 @@ fn test_unresolved_module_diagnostic() { | |||
114 | fn test_unresolved_module_diagnostic_no_diag_for_inline_mode() { | 107 | fn test_unresolved_module_diagnostic_no_diag_for_inline_mode() { |
115 | let snap = analysis(&[("/lib.rs", "mod foo {}")]); | 108 | let snap = analysis(&[("/lib.rs", "mod foo {}")]); |
116 | let diagnostics = snap.diagnostics(FileId(1)); | 109 | let diagnostics = snap.diagnostics(FileId(1)); |
117 | assert_eq_dbg( | 110 | assert_eq_dbg(r#"[]"#, &diagnostics); |
118 | r#"[]"#, | ||
119 | &diagnostics, | ||
120 | ); | ||
121 | } | 111 | } |
122 | 112 | ||
123 | #[test] | 113 | #[test] |
124 | fn test_resolve_parent_module() { | 114 | fn test_resolve_parent_module() { |
125 | let snap = analysis(&[ | 115 | let snap = analysis(&[("/lib.rs", "mod foo;"), ("/foo.rs", "")]); |
126 | ("/lib.rs", "mod foo;"), | ||
127 | ("/foo.rs", ""), | ||
128 | ]); | ||
129 | let symbols = snap.parent_module(FileId(2)); | 116 | let symbols = snap.parent_module(FileId(2)); |
130 | assert_eq_dbg( | 117 | assert_eq_dbg( |
131 | r#"[(FileId(1), FileSymbol { name: "foo", node_range: [0; 8), kind: MODULE })]"#, | 118 | r#"[(FileId(1), FileSymbol { name: "foo", node_range: [0; 8), kind: MODULE })]"#, |
@@ -135,10 +122,7 @@ fn test_resolve_parent_module() { | |||
135 | 122 | ||
136 | #[test] | 123 | #[test] |
137 | fn test_resolve_crate_root() { | 124 | fn test_resolve_crate_root() { |
138 | let mut host = analysis_host(&[ | 125 | let mut host = analysis_host(&[("/lib.rs", "mod foo;"), ("/foo.rs", "")]); |
139 | ("/lib.rs", "mod foo;"), | ||
140 | ("/foo.rs", ""), | ||
141 | ]); | ||
142 | let snap = host.analysis(); | 126 | let snap = host.analysis(); |
143 | assert!(snap.crate_for(FileId(2)).is_empty()); | 127 | assert!(snap.crate_for(FileId(2)).is_empty()); |
144 | 128 | ||
@@ -152,20 +136,18 @@ fn test_resolve_crate_root() { | |||
152 | host.set_crate_graph(crate_graph); | 136 | host.set_crate_graph(crate_graph); |
153 | let snap = host.analysis(); | 137 | let snap = host.analysis(); |
154 | 138 | ||
155 | assert_eq!( | 139 | assert_eq!(snap.crate_for(FileId(2)), vec![CrateId(1)],); |
156 | snap.crate_for(FileId(2)), | ||
157 | vec![CrateId(1)], | ||
158 | ); | ||
159 | } | 140 | } |
160 | 141 | ||
161 | #[test] | 142 | #[test] |
162 | fn test_fn_signature_two_args_first() { | 143 | fn test_fn_signature_two_args_first() { |
163 | let (desc, param) = get_signature( | 144 | let (desc, param) = get_signature( |
164 | r#"fn foo(x: u32, y: u32) -> u32 {x + y} | 145 | r#"fn foo(x: u32, y: u32) -> u32 {x + y} |
165 | fn bar() { foo(<|>3, ); }"#); | 146 | fn bar() { foo(<|>3, ); }"#, |
147 | ); | ||
166 | 148 | ||
167 | assert_eq!(desc.name, "foo".to_string()); | 149 | assert_eq!(desc.name, "foo".to_string()); |
168 | assert_eq!(desc.params, vec!("x".to_string(),"y".to_string())); | 150 | assert_eq!(desc.params, vec!("x".to_string(), "y".to_string())); |
169 | assert_eq!(desc.ret_type, Some("-> u32".into())); | 151 | assert_eq!(desc.ret_type, Some("-> u32".into())); |
170 | assert_eq!(param, Some(0)); | 152 | assert_eq!(param, Some(0)); |
171 | } | 153 | } |
@@ -174,10 +156,11 @@ fn bar() { foo(<|>3, ); }"#); | |||
174 | fn test_fn_signature_two_args_second() { | 156 | fn test_fn_signature_two_args_second() { |
175 | let (desc, param) = get_signature( | 157 | let (desc, param) = get_signature( |
176 | r#"fn foo(x: u32, y: u32) -> u32 {x + y} | 158 | r#"fn foo(x: u32, y: u32) -> u32 {x + y} |
177 | fn bar() { foo(3, <|>); }"#); | 159 | fn bar() { foo(3, <|>); }"#, |
160 | ); | ||
178 | 161 | ||
179 | assert_eq!(desc.name, "foo".to_string()); | 162 | assert_eq!(desc.name, "foo".to_string()); |
180 | assert_eq!(desc.params, vec!("x".to_string(),"y".to_string())); | 163 | assert_eq!(desc.params, vec!("x".to_string(), "y".to_string())); |
181 | assert_eq!(desc.ret_type, Some("-> u32".into())); | 164 | assert_eq!(desc.ret_type, Some("-> u32".into())); |
182 | assert_eq!(param, Some(1)); | 165 | assert_eq!(param, Some(1)); |
183 | } | 166 | } |
@@ -185,8 +168,9 @@ fn bar() { foo(3, <|>); }"#); | |||
185 | #[test] | 168 | #[test] |
186 | fn test_fn_signature_for_impl() { | 169 | fn test_fn_signature_for_impl() { |
187 | let (desc, param) = get_signature( | 170 | let (desc, param) = get_signature( |
188 | r#"struct F; impl F { pub fn new() { F{}} } | 171 | r#"struct F; impl F { pub fn new() { F{}} } |
189 | fn bar() {let _ : F = F::new(<|>);}"#); | 172 | fn bar() {let _ : F = F::new(<|>);}"#, |
173 | ); | ||
190 | 174 | ||
191 | assert_eq!(desc.name, "new".to_string()); | 175 | assert_eq!(desc.name, "new".to_string()); |
192 | assert_eq!(desc.params, Vec::<String>::new()); | 176 | assert_eq!(desc.params, Vec::<String>::new()); |
@@ -197,7 +181,7 @@ fn bar() {let _ : F = F::new(<|>);}"#); | |||
197 | #[test] | 181 | #[test] |
198 | fn test_fn_signature_for_method_self() { | 182 | fn test_fn_signature_for_method_self() { |
199 | let (desc, param) = get_signature( | 183 | let (desc, param) = get_signature( |
200 | r#"struct F; | 184 | r#"struct F; |
201 | impl F { | 185 | impl F { |
202 | pub fn new() -> F{ | 186 | pub fn new() -> F{ |
203 | F{} | 187 | F{} |
@@ -209,7 +193,8 @@ impl F { | |||
209 | fn bar() { | 193 | fn bar() { |
210 | let f : F = F::new(); | 194 | let f : F = F::new(); |
211 | f.do_it(<|>); | 195 | f.do_it(<|>); |
212 | }"#); | 196 | }"#, |
197 | ); | ||
213 | 198 | ||
214 | assert_eq!(desc.name, "do_it".to_string()); | 199 | assert_eq!(desc.name, "do_it".to_string()); |
215 | assert_eq!(desc.params, vec!["&self".to_string()]); | 200 | assert_eq!(desc.params, vec!["&self".to_string()]); |
@@ -220,7 +205,7 @@ fn bar() { | |||
220 | #[test] | 205 | #[test] |
221 | fn test_fn_signature_for_method_with_arg() { | 206 | fn test_fn_signature_for_method_with_arg() { |
222 | let (desc, param) = get_signature( | 207 | let (desc, param) = get_signature( |
223 | r#"struct F; | 208 | r#"struct F; |
224 | impl F { | 209 | impl F { |
225 | pub fn new() -> F{ | 210 | pub fn new() -> F{ |
226 | F{} | 211 | F{} |
@@ -232,7 +217,8 @@ impl F { | |||
232 | fn bar() { | 217 | fn bar() { |
233 | let f : F = F::new(); | 218 | let f : F = F::new(); |
234 | f.do_it(<|>); | 219 | f.do_it(<|>); |
235 | }"#); | 220 | }"#, |
221 | ); | ||
236 | 222 | ||
237 | assert_eq!(desc.name, "do_it".to_string()); | 223 | assert_eq!(desc.name, "do_it".to_string()); |
238 | assert_eq!(desc.params, vec!["&self".to_string(), "x".to_string()]); | 224 | assert_eq!(desc.params, vec!["&self".to_string(), "x".to_string()]); |