aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/tests
diff options
context:
space:
mode:
authorJeremy A. Kolb <[email protected]>2018-10-15 22:44:23 +0100
committerJeremy A. Kolb <[email protected]>2018-10-16 14:41:10 +0100
commit61f3a438d3a729a6be941bca1ff4c6a97a33f221 (patch)
tree6551967cc8c6e921b66071453ad7888a9121d326 /crates/ra_analysis/tests
parent39cb6c6d3f78b193f5873c3492e530bbd24d5dd2 (diff)
Cargo Format
Run `cargo fmt` and ignore generated files
Diffstat (limited to 'crates/ra_analysis/tests')
-rw-r--r--crates/ra_analysis/tests/tests.rs82
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 @@
1extern crate relative_path;
2extern crate ra_analysis; 1extern crate ra_analysis;
3extern crate rustc_hash;
4extern crate ra_editor; 2extern crate ra_editor;
5extern crate ra_syntax; 3extern crate ra_syntax;
4extern crate relative_path;
5extern crate rustc_hash;
6extern crate test_utils; 6extern crate test_utils;
7 7
8use std::{ 8use std::sync::Arc;
9 sync::Arc,
10};
11 9
12use rustc_hash::FxHashMap; 10use ra_analysis::{
11 Analysis, AnalysisHost, CrateGraph, CrateId, FileId, FileResolver, FnDescriptor, JobHandle,
12};
13use relative_path::{RelativePath, RelativePathBuf}; 13use relative_path::{RelativePath, RelativePathBuf};
14use ra_analysis::{Analysis, AnalysisHost, FileId, FileResolver, JobHandle, CrateGraph, CrateId, FnDescriptor}; 14use rustc_hash::FxHashMap;
15use test_utils::{assert_eq_dbg, extract_offset}; 15use test_utils::{assert_eq_dbg, extract_offset};
16 16
17#[derive(Debug)] 17#[derive(Debug)]
18struct FileMap(Vec<(FileId, RelativePathBuf)>); 18struct FileMap(Vec<(FileId, RelativePathBuf)>);
19 19
20impl FileMap { 20impl 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]
73fn test_resolve_module() { 72fn 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() {
114fn test_unresolved_module_diagnostic_no_diag_for_inline_mode() { 107fn 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]
124fn test_resolve_parent_module() { 114fn 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]
137fn test_resolve_crate_root() { 124fn 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]
162fn test_fn_signature_two_args_first() { 143fn test_fn_signature_two_args_first() {
163 let (desc, param) = get_signature( 144 let (desc, param) = get_signature(
164r#"fn foo(x: u32, y: u32) -> u32 {x + y} 145 r#"fn foo(x: u32, y: u32) -> u32 {x + y}
165fn bar() { foo(<|>3, ); }"#); 146fn 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, ); }"#);
174fn test_fn_signature_two_args_second() { 156fn 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}
177fn bar() { foo(3, <|>); }"#); 159fn 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]
186fn test_fn_signature_for_impl() { 169fn test_fn_signature_for_impl() {
187 let (desc, param) = get_signature( 170 let (desc, param) = get_signature(
188r#"struct F; impl F { pub fn new() { F{}} } 171 r#"struct F; impl F { pub fn new() { F{}} }
189fn bar() {let _ : F = F::new(<|>);}"#); 172fn 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]
198fn test_fn_signature_for_method_self() { 182fn test_fn_signature_for_method_self() {
199 let (desc, param) = get_signature( 183 let (desc, param) = get_signature(
200r#"struct F; 184 r#"struct F;
201impl F { 185impl F {
202 pub fn new() -> F{ 186 pub fn new() -> F{
203 F{} 187 F{}
@@ -209,7 +193,8 @@ impl F {
209fn bar() { 193fn 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]
221fn test_fn_signature_for_method_with_arg() { 206fn test_fn_signature_for_method_with_arg() {
222 let (desc, param) = get_signature( 207 let (desc, param) = get_signature(
223r#"struct F; 208 r#"struct F;
224impl F { 209impl F {
225 pub fn new() -> F{ 210 pub fn new() -> F{
226 F{} 211 F{}
@@ -232,7 +217,8 @@ impl F {
232fn bar() { 217fn 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()]);