aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-27 15:55:47 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-27 15:55:47 +0000
commit3f4f50baaa21cb2d0f6c102f1ca521946071a8dc (patch)
tree2de93a338992d963f265ef35b53e55f8d3f1ec66 /crates/ra_hir/src/nameres
parentb2b62b9579e9eefbce27b8a9b799fbd59438ce36 (diff)
parentb775fa285c985821f38f09c25507d80ee793ecfd (diff)
Merge #690
690: Fix module resolution for non standard filenames r=matklad a=regiontog fixes #668 Co-authored-by: Erlend Tobiassen <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/nameres')
-rw-r--r--crates/ra_hir/src/nameres/tests.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index e72781f51..3d420467c 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -19,6 +19,20 @@ 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/// Sets the crate root to the file of the cursor marker
23fn item_map_custom_crate_root(fixture: &str) -> (Arc<ItemMap>, ModuleId) {
24 let (mut db, pos) = MockDatabase::with_position(fixture);
25
26 let mut crate_graph = CrateGraph::default();
27 crate_graph.add_crate_root(pos.file_id);
28 db.set_crate_graph(Arc::new(crate_graph));
29
30 let module = crate::source_binder::module_from_position(&db, pos).unwrap();
31 let krate = module.krate(&db).unwrap();
32 let module_id = module.module_id;
33 (db.item_map(krate.crate_id), module_id)
34}
35
22fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) { 36fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) {
23 let mut lines = map[module_id] 37 let mut lines = map[module_id]
24 .items 38 .items
@@ -134,6 +148,28 @@ fn re_exports() {
134} 148}
135 149
136#[test] 150#[test]
151fn module_resolution_works_for_non_standard_filenames() {
152 let (item_map, module_id) = item_map_custom_crate_root(
153 "
154 //- /my_library.rs
155 mod foo;
156 use self::foo::Bar;
157 <|>
158 //- /foo/mod.rs
159 pub struct Bar;
160 ",
161 );
162 check_module_item_map(
163 &item_map,
164 module_id,
165 "
166 Bar: t v
167 foo: t
168 ",
169 );
170}
171
172#[test]
137fn name_res_works_for_broken_modules() { 173fn name_res_works_for_broken_modules() {
138 covers!(name_res_works_for_broken_modules); 174 covers!(name_res_works_for_broken_modules);
139 let (item_map, module_id) = item_map( 175 let (item_map, module_id) = item_map(