diff options
author | Erlend Tobiassen <[email protected]> | 2019-01-27 13:51:26 +0000 |
---|---|---|
committer | Erlend Tobiassen <[email protected]> | 2019-01-27 14:15:56 +0000 |
commit | 683e5e64f42b6c74596015c5d19e2eab186fe68d (patch) | |
tree | 4cb6df38e804232bf504e9dd4b92694a5310beb4 /crates/ra_hir/src/nameres | |
parent | 964086e0d4874d7e60eb3607220e486ec4b51f86 (diff) |
Test non standard crate root
Diffstat (limited to 'crates/ra_hir/src/nameres')
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index e72781f51..5b161cf49 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs | |||
@@ -19,6 +19,19 @@ fn item_map(fixture: &str) -> (Arc<ItemMap>, ModuleId) { | |||
19 | (db.item_map(krate.crate_id), module_id) | 19 | (db.item_map(krate.crate_id), module_id) |
20 | } | 20 | } |
21 | 21 | ||
22 | fn item_map_custom_crate_root(fixture: &str, root: &str) -> (Arc<ItemMap>, ModuleId) { | ||
23 | let (mut db, pos) = MockDatabase::with_position(fixture); | ||
24 | |||
25 | let mut crate_graph = CrateGraph::default(); | ||
26 | crate_graph.add_crate_root(db.file_id(root)); | ||
27 | db.set_crate_graph(Arc::new(crate_graph)); | ||
28 | |||
29 | let module = crate::source_binder::module_from_position(&db, dbg!(pos)).unwrap(); | ||
30 | let krate = module.krate(&db).unwrap(); | ||
31 | let module_id = module.module_id; | ||
32 | (db.item_map(krate.crate_id), module_id) | ||
33 | } | ||
34 | |||
22 | fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) { | 35 | fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) { |
23 | let mut lines = map[module_id] | 36 | let mut lines = map[module_id] |
24 | .items | 37 | .items |
@@ -134,6 +147,31 @@ fn re_exports() { | |||
134 | } | 147 | } |
135 | 148 | ||
136 | #[test] | 149 | #[test] |
150 | fn module_resolution_works_for_non_standard_filenames() { | ||
151 | let (item_map, module_id) = item_map_custom_crate_root( | ||
152 | " | ||
153 | //- /my_library.rs | ||
154 | mod foo; | ||
155 | |||
156 | use self::foo::Bar; | ||
157 | <|> | ||
158 | |||
159 | //- /foo/mod.rs | ||
160 | pub struct Bar; | ||
161 | ", | ||
162 | "/my_library.rs", | ||
163 | ); | ||
164 | check_module_item_map( | ||
165 | &item_map, | ||
166 | module_id, | ||
167 | " | ||
168 | Bar: t v | ||
169 | foo: t | ||
170 | ", | ||
171 | ); | ||
172 | } | ||
173 | |||
174 | #[test] | ||
137 | fn name_res_works_for_broken_modules() { | 175 | fn name_res_works_for_broken_modules() { |
138 | covers!(name_res_works_for_broken_modules); | 176 | covers!(name_res_works_for_broken_modules); |
139 | let (item_map, module_id) = item_map( | 177 | let (item_map, module_id) = item_map( |