aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/tests
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-10-20 20:43:36 +0100
committerAleksey Kladov <[email protected]>2018-10-20 20:43:36 +0100
commit8bb4380448f3ef5391beff1b9f64bf956c43b61f (patch)
treed07689e1bef8702f85b898256410238a1e0bc197 /crates/ra_analysis/tests
parent6e88aaef5d49c8ec7b6ffe6b41457c3a028b4eb0 (diff)
Fix tests
Diffstat (limited to 'crates/ra_analysis/tests')
-rw-r--r--crates/ra_analysis/tests/tests.rs31
1 files changed, 14 insertions, 17 deletions
diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs
index 0c2c69ea0..7ae3d0eeb 100644
--- a/crates/ra_analysis/tests/tests.rs
+++ b/crates/ra_analysis/tests/tests.rs
@@ -7,15 +7,15 @@ extern crate test_utils;
7 7
8use std::sync::Arc; 8use std::sync::Arc;
9 9
10use ra_analysis::{
11 Analysis, AnalysisHost, CrateGraph, CrateId, FileId, FileResolver, FnDescriptor, JobHandle,
12};
13use ra_syntax::TextRange; 10use ra_syntax::TextRange;
14
15use relative_path::{RelativePath, RelativePathBuf}; 11use relative_path::{RelativePath, RelativePathBuf};
16use rustc_hash::FxHashMap; 12use rustc_hash::FxHashMap;
17use test_utils::{assert_eq_dbg, extract_offset}; 13use test_utils::{assert_eq_dbg, extract_offset};
18 14
15use ra_analysis::{
16 Analysis, AnalysisHost, CrateGraph, CrateId, FileId, FileResolver, FnDescriptor,
17};
18
19#[derive(Debug)] 19#[derive(Debug)]
20struct FileMap(Vec<(FileId, RelativePathBuf)>); 20struct FileMap(Vec<(FileId, RelativePathBuf)>);
21 21
@@ -64,24 +64,22 @@ fn get_signature(text: &str) -> (FnDescriptor, Option<usize>) {
64 let (offset, code) = extract_offset(text); 64 let (offset, code) = extract_offset(text);
65 let code = code.as_str(); 65 let code = code.as_str();
66 66
67 let (_handle, token) = JobHandle::new();
68 let snap = analysis(&[("/lib.rs", code)]); 67 let snap = analysis(&[("/lib.rs", code)]);
69 68
70 snap.resolve_callable(FileId(1), offset, &token).unwrap() 69 snap.resolve_callable(FileId(1), offset).unwrap().unwrap()
71} 70}
72 71
73#[test] 72#[test]
74fn test_resolve_module() { 73fn test_resolve_module() {
75 let snap = analysis(&[("/lib.rs", "mod foo;"), ("/foo.rs", "")]); 74 let snap = analysis(&[("/lib.rs", "mod foo;"), ("/foo.rs", "")]);
76 let (_handle, token) = JobHandle::new(); 75 let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into()).unwrap();
77 let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into(), &token);
78 assert_eq_dbg( 76 assert_eq_dbg(
79 r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#, 77 r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#,
80 &symbols, 78 &symbols,
81 ); 79 );
82 80
83 let snap = analysis(&[("/lib.rs", "mod foo;"), ("/foo/mod.rs", "")]); 81 let snap = analysis(&[("/lib.rs", "mod foo;"), ("/foo/mod.rs", "")]);
84 let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into(), &token); 82 let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into()).unwrap();
85 assert_eq_dbg( 83 assert_eq_dbg(
86 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 })]"#,
87 &symbols, 85 &symbols,
@@ -91,7 +89,7 @@ fn test_resolve_module() {
91#[test] 89#[test]
92fn test_unresolved_module_diagnostic() { 90fn test_unresolved_module_diagnostic() {
93 let snap = analysis(&[("/lib.rs", "mod foo;")]); 91 let snap = analysis(&[("/lib.rs", "mod foo;")]);
94 let diagnostics = snap.diagnostics(FileId(1)); 92 let diagnostics = snap.diagnostics(FileId(1)).unwrap();
95 assert_eq_dbg( 93 assert_eq_dbg(
96 r#"[Diagnostic { 94 r#"[Diagnostic {
97 message: "unresolved module", 95 message: "unresolved module",
@@ -108,14 +106,14 @@ fn test_unresolved_module_diagnostic() {
108#[test] 106#[test]
109fn test_unresolved_module_diagnostic_no_diag_for_inline_mode() { 107fn test_unresolved_module_diagnostic_no_diag_for_inline_mode() {
110 let snap = analysis(&[("/lib.rs", "mod foo {}")]); 108 let snap = analysis(&[("/lib.rs", "mod foo {}")]);
111 let diagnostics = snap.diagnostics(FileId(1)); 109 let diagnostics = snap.diagnostics(FileId(1)).unwrap();
112 assert_eq_dbg(r#"[]"#, &diagnostics); 110 assert_eq_dbg(r#"[]"#, &diagnostics);
113} 111}
114 112
115#[test] 113#[test]
116fn test_resolve_parent_module() { 114fn test_resolve_parent_module() {
117 let snap = analysis(&[("/lib.rs", "mod foo;"), ("/foo.rs", "")]); 115 let snap = analysis(&[("/lib.rs", "mod foo;"), ("/foo.rs", "")]);
118 let symbols = snap.parent_module(FileId(2)); 116 let symbols = snap.parent_module(FileId(2)).unwrap();
119 assert_eq_dbg( 117 assert_eq_dbg(
120 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 })]"#,
121 &symbols, 119 &symbols,
@@ -126,7 +124,7 @@ fn test_resolve_parent_module() {
126fn test_resolve_crate_root() { 124fn test_resolve_crate_root() {
127 let mut host = analysis_host(&[("/lib.rs", "mod foo;"), ("/foo.rs", "")]); 125 let mut host = analysis_host(&[("/lib.rs", "mod foo;"), ("/foo.rs", "")]);
128 let snap = host.analysis(); 126 let snap = host.analysis();
129 assert!(snap.crate_for(FileId(2)).is_empty()); 127 assert!(snap.crate_for(FileId(2)).unwrap().is_empty());
130 128
131 let crate_graph = CrateGraph { 129 let crate_graph = CrateGraph {
132 crate_roots: { 130 crate_roots: {
@@ -138,7 +136,7 @@ fn test_resolve_crate_root() {
138 host.set_crate_graph(crate_graph); 136 host.set_crate_graph(crate_graph);
139 let snap = host.analysis(); 137 let snap = host.analysis();
140 138
141 assert_eq!(snap.crate_for(FileId(2)), vec![CrateId(1)],); 139 assert_eq!(snap.crate_for(FileId(2)).unwrap(), vec![CrateId(1)],);
142} 140}
143 141
144#[test] 142#[test]
@@ -232,10 +230,9 @@ fn get_all_refs(text: &str) -> Vec<(FileId, TextRange)> {
232 let (offset, code) = extract_offset(text); 230 let (offset, code) = extract_offset(text);
233 let code = code.as_str(); 231 let code = code.as_str();
234 232
235 let (_handle, token) = JobHandle::new();
236 let snap = analysis(&[("/lib.rs", code)]); 233 let snap = analysis(&[("/lib.rs", code)]);
237 234
238 snap.find_all_refs(FileId(1), offset, &token) 235 snap.find_all_refs(FileId(1), offset).unwrap()
239} 236}
240 237
241#[test] 238#[test]
@@ -266,4 +263,4 @@ fn test_find_all_refs_for_param_inside() {
266 263
267 let refs = get_all_refs(code); 264 let refs = get_all_refs(code);
268 assert_eq!(refs.len(), 2); 265 assert_eq!(refs.len(), 2);
269} \ No newline at end of file 266}