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