diff options
Diffstat (limited to 'crates/libanalysis/tests')
-rw-r--r-- | crates/libanalysis/tests/tests.rs | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/crates/libanalysis/tests/tests.rs b/crates/libanalysis/tests/tests.rs index 887e13fa3..c098c8e8c 100644 --- a/crates/libanalysis/tests/tests.rs +++ b/crates/libanalysis/tests/tests.rs | |||
@@ -2,10 +2,13 @@ extern crate libanalysis; | |||
2 | extern crate relative_path; | 2 | extern crate relative_path; |
3 | extern crate test_utils; | 3 | extern crate test_utils; |
4 | 4 | ||
5 | use std::path::{Path}; | 5 | use std::{ |
6 | collections::HashMap, | ||
7 | path::{Path}, | ||
8 | }; | ||
6 | 9 | ||
7 | use relative_path::RelativePath; | 10 | use relative_path::RelativePath; |
8 | use libanalysis::{AnalysisHost, FileId, FileResolver, JobHandle}; | 11 | use libanalysis::{AnalysisHost, FileId, FileResolver, JobHandle, CrateGraph, CrateId}; |
9 | use test_utils::assert_eq_dbg; | 12 | use test_utils::assert_eq_dbg; |
10 | 13 | ||
11 | struct FileMap(&'static [(u32, &'static str)]); | 14 | struct FileMap(&'static [(u32, &'static str)]); |
@@ -112,3 +115,34 @@ fn test_resolve_parent_module() { | |||
112 | &symbols, | 115 | &symbols, |
113 | ); | 116 | ); |
114 | } | 117 | } |
118 | |||
119 | #[test] | ||
120 | fn test_resolve_crate_root() { | ||
121 | let mut world = AnalysisHost::new(); | ||
122 | world.change_file(FileId(1), Some("mod foo;".to_string())); | ||
123 | world.change_file(FileId(2), Some("".to_string())); | ||
124 | |||
125 | let snap = world.analysis(FileMap(&[ | ||
126 | (1, "/lib.rs"), | ||
127 | (2, "/foo.rs"), | ||
128 | ])); | ||
129 | assert!(snap.crate_root(FileId(2)).is_empty()); | ||
130 | |||
131 | let crate_graph = CrateGraph { | ||
132 | crate_roots: { | ||
133 | let mut m = HashMap::new(); | ||
134 | m.insert(CrateId(1), FileId(1)); | ||
135 | m | ||
136 | }, | ||
137 | }; | ||
138 | world.set_crate_graph(crate_graph); | ||
139 | |||
140 | let snap = world.analysis(FileMap(&[ | ||
141 | (1, "/lib.rs"), | ||
142 | (2, "/foo.rs"), | ||
143 | ])); | ||
144 | assert_eq!( | ||
145 | snap.crate_root(FileId(2)), | ||
146 | vec![CrateId(1)], | ||
147 | ); | ||
148 | } | ||