aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/tests
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-10-31 20:41:43 +0000
committerAleksey Kladov <[email protected]>2018-10-31 20:41:43 +0000
commit6be50f7d5de3737464853a589673375fc0cafa97 (patch)
tree2c6da7f3a1234c3f2fd3f330d2c9445953979598 /crates/ra_analysis/tests
parent857c1650efdb51650458f9ec1119adaa49b34371 (diff)
Reformat all
Diffstat (limited to 'crates/ra_analysis/tests')
-rw-r--r--crates/ra_analysis/tests/tests.rs105
1 files changed, 73 insertions, 32 deletions
diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs
index 22d27cdbe..c2754c8e4 100644
--- a/crates/ra_analysis/tests/tests.rs
+++ b/crates/ra_analysis/tests/tests.rs
@@ -5,42 +5,53 @@ extern crate relative_path;
5extern crate rustc_hash; 5extern crate rustc_hash;
6extern crate test_utils; 6extern crate test_utils;
7 7
8use ra_syntax::{TextRange}; 8use ra_syntax::TextRange;
9use test_utils::{assert_eq_dbg}; 9use test_utils::assert_eq_dbg;
10 10
11use ra_analysis::{ 11use ra_analysis::{
12 mock_analysis::{analysis_and_position, single_file, single_file_with_position, MockAnalysis},
12 AnalysisChange, CrateGraph, FileId, FnDescriptor, 13 AnalysisChange, CrateGraph, FileId, FnDescriptor,
13 mock_analysis::{MockAnalysis, single_file, single_file_with_position, analysis_and_position},
14}; 14};
15 15
16fn get_signature(text: &str) -> (FnDescriptor, Option<usize>) { 16fn get_signature(text: &str) -> (FnDescriptor, Option<usize>) {
17 let (analysis, position) = single_file_with_position(text); 17 let (analysis, position) = single_file_with_position(text);
18 analysis.resolve_callable(position.file_id, position.offset).unwrap().unwrap() 18 analysis
19 .resolve_callable(position.file_id, position.offset)
20 .unwrap()
21 .unwrap()
19} 22}
20 23
21#[test] 24#[test]
22fn test_resolve_module() { 25fn test_resolve_module() {
23 let (analysis, pos) = analysis_and_position(" 26 let (analysis, pos) = analysis_and_position(
27 "
24 //- /lib.rs 28 //- /lib.rs
25 mod <|>foo; 29 mod <|>foo;
26 //- /foo.rs 30 //- /foo.rs
27 // empty 31 // empty
28 "); 32 ",
33 );
29 34
30 let symbols = analysis.approximately_resolve_symbol(pos.file_id, pos.offset).unwrap(); 35 let symbols = analysis
36 .approximately_resolve_symbol(pos.file_id, pos.offset)
37 .unwrap();
31 assert_eq_dbg( 38 assert_eq_dbg(
32 r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#, 39 r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#,
33 &symbols, 40 &symbols,
34 ); 41 );
35 42
36 let (analysis, pos) = analysis_and_position(" 43 let (analysis, pos) = analysis_and_position(
44 "
37 //- /lib.rs 45 //- /lib.rs
38 mod <|>foo; 46 mod <|>foo;
39 //- /foo/mod.rs 47 //- /foo/mod.rs
40 // empty 48 // empty
41 "); 49 ",
50 );
42 51
43 let symbols = analysis.approximately_resolve_symbol(pos.file_id, pos.offset).unwrap(); 52 let symbols = analysis
53 .approximately_resolve_symbol(pos.file_id, pos.offset)
54 .unwrap();
44 assert_eq_dbg( 55 assert_eq_dbg(
45 r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#, 56 r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#,
46 &symbols, 57 &symbols,
@@ -73,12 +84,14 @@ fn test_unresolved_module_diagnostic_no_diag_for_inline_mode() {
73 84
74#[test] 85#[test]
75fn test_resolve_parent_module() { 86fn test_resolve_parent_module() {
76 let (analysis, pos) = analysis_and_position(" 87 let (analysis, pos) = analysis_and_position(
88 "
77 //- /lib.rs 89 //- /lib.rs
78 mod foo; 90 mod foo;
79 //- /foo.rs 91 //- /foo.rs
80 <|>// empty 92 <|>// empty
81 "); 93 ",
94 );
82 let symbols = analysis.parent_module(pos.file_id).unwrap(); 95 let symbols = analysis.parent_module(pos.file_id).unwrap();
83 assert_eq_dbg( 96 assert_eq_dbg(
84 r#"[(FileId(1), FileSymbol { name: "foo", node_range: [0; 8), kind: MODULE })]"#, 97 r#"[(FileId(1), FileSymbol { name: "foo", node_range: [0; 8), kind: MODULE })]"#,
@@ -88,12 +101,14 @@ fn test_resolve_parent_module() {
88 101
89#[test] 102#[test]
90fn test_resolve_crate_root() { 103fn test_resolve_crate_root() {
91 let mock = MockAnalysis::with_files(" 104 let mock = MockAnalysis::with_files(
105 "
92 //- /lib.rs 106 //- /lib.rs
93 mod foo; 107 mod foo;
94 //- /foo.rs 108 //- /foo.rs
95 // emtpy <|> 109 // emtpy <|>
96 "); 110 ",
111 );
97 let root_file = mock.id_of("/lib.rs"); 112 let root_file = mock.id_of("/lib.rs");
98 let mod_file = mock.id_of("/foo.rs"); 113 let mod_file = mock.id_of("/foo.rs");
99 let mut host = mock.analysis_host(); 114 let mut host = mock.analysis_host();
@@ -245,8 +260,10 @@ pub fn do() {
245 assert_eq!(desc.ret_type, Some("-> i32".to_string())); 260 assert_eq!(desc.ret_type, Some("-> i32".to_string()));
246 assert_eq!(param, Some(0)); 261 assert_eq!(param, Some(0));
247 assert_eq!(desc.label, "pub fn add_one(x: i32) -> i32".to_string()); 262 assert_eq!(desc.label, "pub fn add_one(x: i32) -> i32".to_string());
248 assert_eq!(desc.doc, Some( 263 assert_eq!(
249r#"Adds one to the number given. 264 desc.doc,
265 Some(
266 r#"Adds one to the number given.
250 267
251# Examples 268# Examples
252 269
@@ -254,7 +271,10 @@ r#"Adds one to the number given.
254let five = 5; 271let five = 5;
255 272
256assert_eq!(6, my_crate::add_one(5)); 273assert_eq!(6, my_crate::add_one(5));
257```"#.into())); 274```"#
275 .into()
276 )
277 );
258} 278}
259 279
260#[test] 280#[test]
@@ -280,15 +300,18 @@ impl addr {
280pub fn do_it() { 300pub fn do_it() {
281 addr {}; 301 addr {};
282 addr::add_one(<|>); 302 addr::add_one(<|>);
283}"#); 303}"#,
304 );
284 305
285 assert_eq!(desc.name, "add_one".to_string()); 306 assert_eq!(desc.name, "add_one".to_string());
286 assert_eq!(desc.params, vec!["x".to_string()]); 307 assert_eq!(desc.params, vec!["x".to_string()]);
287 assert_eq!(desc.ret_type, Some("-> i32".to_string())); 308 assert_eq!(desc.ret_type, Some("-> i32".to_string()));
288 assert_eq!(param, Some(0)); 309 assert_eq!(param, Some(0));
289 assert_eq!(desc.label, "pub fn add_one(x: i32) -> i32".to_string()); 310 assert_eq!(desc.label, "pub fn add_one(x: i32) -> i32".to_string());
290 assert_eq!(desc.doc, Some( 311 assert_eq!(
291r#"Adds one to the number given. 312 desc.doc,
313 Some(
314 r#"Adds one to the number given.
292 315
293# Examples 316# Examples
294 317
@@ -296,7 +319,10 @@ r#"Adds one to the number given.
296let five = 5; 319let five = 5;
297 320
298assert_eq!(6, my_crate::add_one(5)); 321assert_eq!(6, my_crate::add_one(5));
299```"#.into())); 322```"#
323 .into()
324 )
325 );
300} 326}
301 327
302#[test] 328#[test]
@@ -329,22 +355,32 @@ pub fn foo() {
329 r.finished(<|>); 355 r.finished(<|>);
330} 356}
331 357
332"#); 358"#,
359 );
333 360
334 assert_eq!(desc.name, "finished".to_string()); 361 assert_eq!(desc.name, "finished".to_string());
335 assert_eq!(desc.params, vec!["&mut self".to_string(), "ctx".to_string()]); 362 assert_eq!(
363 desc.params,
364 vec!["&mut self".to_string(), "ctx".to_string()]
365 );
336 assert_eq!(desc.ret_type, None); 366 assert_eq!(desc.ret_type, None);
337 assert_eq!(param, Some(1)); 367 assert_eq!(param, Some(1));
338 assert_eq!(desc.doc, Some( 368 assert_eq!(
339r#"Method is called when writer finishes. 369 desc.doc,
340 370 Some(
341By default this method stops actor's `Context`."#.into())); 371 r#"Method is called when writer finishes.
372
373By default this method stops actor's `Context`."#
374 .into()
375 )
376 );
342} 377}
343 378
344
345fn get_all_refs(text: &str) -> Vec<(FileId, TextRange)> { 379fn get_all_refs(text: &str) -> Vec<(FileId, TextRange)> {
346 let (analysis, position) = single_file_with_position(text); 380 let (analysis, position) = single_file_with_position(text);
347 analysis.find_all_refs(position.file_id, position.offset).unwrap() 381 analysis
382 .find_all_refs(position.file_id, position.offset)
383 .unwrap()
348} 384}
349 385
350#[test] 386#[test]
@@ -390,14 +426,19 @@ fn test_find_all_refs_for_fn_param() {
390 426
391#[test] 427#[test]
392fn test_complete_crate_path() { 428fn test_complete_crate_path() {
393 let (analysis, position) = analysis_and_position(" 429 let (analysis, position) = analysis_and_position(
430 "
394 //- /lib.rs 431 //- /lib.rs
395 mod foo; 432 mod foo;
396 struct Spam; 433 struct Spam;
397 //- /foo.rs 434 //- /foo.rs
398 use crate::Sp<|> 435 use crate::Sp<|>
399 "); 436 ",
400 let completions = analysis.completions(position.file_id, position.offset).unwrap().unwrap(); 437 );
438 let completions = analysis
439 .completions(position.file_id, position.offset)
440 .unwrap()
441 .unwrap();
401 assert_eq_dbg( 442 assert_eq_dbg(
402 r#"[CompletionItem { label: "foo", lookup: None, snippet: None }, 443 r#"[CompletionItem { label: "foo", lookup: None, snippet: None },
403 CompletionItem { label: "Spam", lookup: None, snippet: None }]"#, 444 CompletionItem { label: "Spam", lookup: None, snippet: None }]"#,