diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-10 20:15:41 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-10 20:15:41 +0000 |
commit | ffd407affff967884fd51a977335469e819c7194 (patch) | |
tree | de0f95ec9e49ee97148047622e333353f24c1433 /crates/ra_hir/src/nameres | |
parent | b952c270ee87cc36500b3bb03bab9268f2184d1a (diff) | |
parent | 2f24e740db3365afac56aad3e8a533340369ef7d (diff) |
Merge #778
778: Glob imports r=matklad a=flodiebold
This implements glob imports, completing #231 :)
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/nameres')
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 3dfad6bf2..9c0e4ef29 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs | |||
@@ -165,6 +165,126 @@ fn re_exports() { | |||
165 | } | 165 | } |
166 | 166 | ||
167 | #[test] | 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 | covers!(glob_across_crates); | ||
255 | let (mut db, sr) = MockDatabase::with_files( | ||
256 | " | ||
257 | //- /main.rs | ||
258 | use test_crate::*; | ||
259 | |||
260 | //- /lib.rs | ||
261 | pub struct Baz; | ||
262 | ", | ||
263 | ); | ||
264 | let main_id = sr.files[RelativePath::new("/main.rs")]; | ||
265 | let lib_id = sr.files[RelativePath::new("/lib.rs")]; | ||
266 | |||
267 | let mut crate_graph = CrateGraph::default(); | ||
268 | let main_crate = crate_graph.add_crate_root(main_id); | ||
269 | let lib_crate = crate_graph.add_crate_root(lib_id); | ||
270 | crate_graph.add_dep(main_crate, "test_crate".into(), lib_crate).unwrap(); | ||
271 | |||
272 | db.set_crate_graph(Arc::new(crate_graph)); | ||
273 | |||
274 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); | ||
275 | let krate = module.krate(&db).unwrap(); | ||
276 | let item_map = db.item_map(krate); | ||
277 | |||
278 | check_module_item_map( | ||
279 | &item_map, | ||
280 | module.module_id, | ||
281 | " | ||
282 | Baz: t v | ||
283 | ", | ||
284 | ); | ||
285 | } | ||
286 | |||
287 | #[test] | ||
168 | fn module_resolution_works_for_non_standard_filenames() { | 288 | fn module_resolution_works_for_non_standard_filenames() { |
169 | let (item_map, module_id) = item_map_custom_crate_root( | 289 | let (item_map, module_id) = item_map_custom_crate_root( |
170 | " | 290 | " |