diff options
Diffstat (limited to 'crates/ra_analysis/tests')
-rw-r--r-- | crates/ra_analysis/tests/tests.rs | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs index 52fae71ae..806e1fb34 100644 --- a/crates/ra_analysis/tests/tests.rs +++ b/crates/ra_analysis/tests/tests.rs | |||
@@ -5,15 +5,16 @@ extern crate relative_path; | |||
5 | extern crate rustc_hash; | 5 | extern crate rustc_hash; |
6 | extern crate test_utils; | 6 | extern crate test_utils; |
7 | 7 | ||
8 | use std::sync::Arc; | 8 | use std::{ |
9 | sync::Arc, | ||
10 | }; | ||
9 | 11 | ||
10 | use ra_syntax::TextRange; | 12 | use ra_syntax::TextRange; |
11 | use relative_path::{RelativePath, RelativePathBuf}; | 13 | use relative_path::{RelativePath, RelativePathBuf}; |
12 | use rustc_hash::FxHashMap; | ||
13 | use test_utils::{assert_eq_dbg, extract_offset}; | 14 | use test_utils::{assert_eq_dbg, extract_offset}; |
14 | 15 | ||
15 | use ra_analysis::{ | 16 | use ra_analysis::{ |
16 | Analysis, AnalysisHost, CrateGraph, CrateId, FileId, FileResolver, FnDescriptor, | 17 | AnalysisChange, Analysis, AnalysisHost, CrateGraph, CrateId, FileId, FileResolver, FnDescriptor, |
17 | }; | 18 | }; |
18 | 19 | ||
19 | #[derive(Debug)] | 20 | #[derive(Debug)] |
@@ -45,14 +46,16 @@ impl FileResolver for FileMap { | |||
45 | fn analysis_host(files: &[(&str, &str)]) -> AnalysisHost { | 46 | fn analysis_host(files: &[(&str, &str)]) -> AnalysisHost { |
46 | let mut host = AnalysisHost::new(); | 47 | let mut host = AnalysisHost::new(); |
47 | let mut file_map = Vec::new(); | 48 | let mut file_map = Vec::new(); |
49 | let mut change = AnalysisChange::new(); | ||
48 | for (id, &(path, contents)) in files.iter().enumerate() { | 50 | for (id, &(path, contents)) in files.iter().enumerate() { |
49 | let file_id = FileId((id + 1) as u32); | 51 | let file_id = FileId((id + 1) as u32); |
50 | assert!(path.starts_with('/')); | 52 | assert!(path.starts_with('/')); |
51 | let path = RelativePathBuf::from_path(&path[1..]).unwrap(); | 53 | let path = RelativePathBuf::from_path(&path[1..]).unwrap(); |
52 | host.change_file(file_id, Some(contents.to_string())); | 54 | change.add_file(file_id, contents.to_string()); |
53 | file_map.push((file_id, path)); | 55 | file_map.push((file_id, path)); |
54 | } | 56 | } |
55 | host.set_file_resolver(Arc::new(FileMap(file_map))); | 57 | change.set_file_resolver(Arc::new(FileMap(file_map))); |
58 | host.apply_change(change); | ||
56 | host | 59 | host |
57 | } | 60 | } |
58 | 61 | ||
@@ -126,17 +129,17 @@ fn test_resolve_crate_root() { | |||
126 | let snap = host.analysis(); | 129 | let snap = host.analysis(); |
127 | assert!(snap.crate_for(FileId(2)).unwrap().is_empty()); | 130 | assert!(snap.crate_for(FileId(2)).unwrap().is_empty()); |
128 | 131 | ||
129 | let crate_graph = CrateGraph { | 132 | let crate_graph = { |
130 | crate_roots: { | 133 | let mut g = CrateGraph::new(); |
131 | let mut m = FxHashMap::default(); | 134 | g.add_crate_root(FileId(1)); |
132 | m.insert(CrateId(1), FileId(1)); | 135 | g |
133 | m | ||
134 | }, | ||
135 | }; | 136 | }; |
136 | host.set_crate_graph(crate_graph); | 137 | let mut change = AnalysisChange::new(); |
138 | change.set_crate_graph(crate_graph); | ||
139 | host.apply_change(change); | ||
137 | let snap = host.analysis(); | 140 | let snap = host.analysis(); |
138 | 141 | ||
139 | assert_eq!(snap.crate_for(FileId(2)).unwrap(), vec![CrateId(1)],); | 142 | assert_eq!(snap.crate_for(FileId(2)).unwrap(), vec![CrateId(0)],); |
140 | } | 143 | } |
141 | 144 | ||
142 | #[test] | 145 | #[test] |