aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis/tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libanalysis/tests')
-rw-r--r--crates/libanalysis/tests/tests.rs38
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;
2extern crate relative_path; 2extern crate relative_path;
3extern crate test_utils; 3extern crate test_utils;
4 4
5use std::path::{Path}; 5use std::{
6 collections::HashMap,
7 path::{Path},
8};
6 9
7use relative_path::RelativePath; 10use relative_path::RelativePath;
8use libanalysis::{AnalysisHost, FileId, FileResolver, JobHandle}; 11use libanalysis::{AnalysisHost, FileId, FileResolver, JobHandle, CrateGraph, CrateId};
9use test_utils::assert_eq_dbg; 12use test_utils::assert_eq_dbg;
10 13
11struct FileMap(&'static [(u32, &'static str)]); 14struct 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]
120fn 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}