Skip to content

Commit 35cfb41

Browse files
committed
Add some tests
1 parent 8e4be27 commit 35cfb41

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

crates/ra_hir/src/marks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ test_utils::marks!(
44
type_var_cycles_resolve_completely
55
type_var_cycles_resolve_as_possible
66
type_var_resolves_to_int_var
7+
glob_enum
78
);

crates/ra_hir/src/nameres/tests.rs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,125 @@ fn re_exports() {
164164
);
165165
}
166166

167+
#[test]
168+
fn glob_1() {
169+
let (item_map, module_id) = item_map(
170+
"
171+
//- /lib.rs
172+
mod foo;
173+
use foo::*;
174+
<|>
175+
176+
//- /foo/mod.rs
177+
pub mod bar;
178+
pub use self::bar::Baz;
179+
pub struct Foo;
180+
181+
//- /foo/bar.rs
182+
pub struct Baz;
183+
",
184+
);
185+
check_module_item_map(
186+
&item_map,
187+
module_id,
188+
"
189+
Baz: t v
190+
Foo: t v
191+
bar: t
192+
foo: t
193+
",
194+
);
195+
}
196+
197+
#[test]
198+
fn glob_2() {
199+
let (item_map, module_id) = item_map(
200+
"
201+
//- /lib.rs
202+
mod foo;
203+
use foo::*;
204+
<|>
205+
206+
//- /foo/mod.rs
207+
pub mod bar;
208+
pub use self::bar::*;
209+
pub struct Foo;
210+
211+
//- /foo/bar.rs
212+
pub struct Baz;
213+
pub use super::*;
214+
",
215+
);
216+
check_module_item_map(
217+
&item_map,
218+
module_id,
219+
"
220+
Baz: t v
221+
Foo: t v
222+
bar: t
223+
foo: t
224+
",
225+
);
226+
}
227+
228+
#[test]
229+
fn glob_enum() {
230+
covers!(glob_enum);
231+
let (item_map, module_id) = item_map(
232+
"
233+
//- /lib.rs
234+
enum Foo {
235+
Bar, Baz
236+
}
237+
use self::Foo::*;
238+
<|>
239+
",
240+
);
241+
check_module_item_map(
242+
&item_map,
243+
module_id,
244+
"
245+
Bar: t v
246+
Baz: t v
247+
Foo: t
248+
",
249+
);
250+
}
251+
252+
#[test]
253+
fn glob_across_crates() {
254+
let (mut db, sr) = MockDatabase::with_files(
255+
"
256+
//- /main.rs
257+
use test_crate::*;
258+
259+
//- /lib.rs
260+
pub struct Baz;
261+
",
262+
);
263+
let main_id = sr.files[RelativePath::new("/main.rs")];
264+
let lib_id = sr.files[RelativePath::new("/lib.rs")];
265+
266+
let mut crate_graph = CrateGraph::default();
267+
let main_crate = crate_graph.add_crate_root(main_id);
268+
let lib_crate = crate_graph.add_crate_root(lib_id);
269+
crate_graph.add_dep(main_crate, "test_crate".into(), lib_crate).unwrap();
270+
271+
db.set_crate_graph(Arc::new(crate_graph));
272+
273+
let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap();
274+
let krate = module.krate(&db).unwrap();
275+
let item_map = db.item_map(krate);
276+
277+
check_module_item_map(
278+
&item_map,
279+
module.module_id,
280+
"
281+
Baz: t v
282+
",
283+
);
284+
}
285+
167286
#[test]
168287
fn module_resolution_works_for_non_standard_filenames() {
169288
let (item_map, module_id) = item_map_custom_crate_root(

0 commit comments

Comments
 (0)