aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-02-10 14:16:23 +0000
committerFlorian Diebold <[email protected]>2019-02-10 15:20:01 +0000
commit35cfb418baa8c7f37a27152bcb1894275c2abee2 (patch)
tree4fe63f3cabd1868bc41634818f9a212c64604fd7 /crates
parent8e4be2708635818aa3e210f0e39fb871cc433004 (diff)
Add some tests
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/marks.rs1
-rw-r--r--crates/ra_hir/src/nameres/tests.rs119
2 files changed, 120 insertions, 0 deletions
diff --git a/crates/ra_hir/src/marks.rs b/crates/ra_hir/src/marks.rs
index aba0c9968..5732eeccf 100644
--- a/crates/ra_hir/src/marks.rs
+++ b/crates/ra_hir/src/marks.rs
@@ -4,4 +4,5 @@ test_utils::marks!(
4 type_var_cycles_resolve_completely 4 type_var_cycles_resolve_completely
5 type_var_cycles_resolve_as_possible 5 type_var_cycles_resolve_as_possible
6 type_var_resolves_to_int_var 6 type_var_resolves_to_int_var
7 glob_enum
7); 8);
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index 3dfad6bf2..91566fc98 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -165,6 +165,125 @@ fn re_exports() {
165} 165}
166 166
167#[test] 167#[test]
168fn 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]
198fn 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]
229fn 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]
253fn 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
286#[test]
168fn module_resolution_works_for_non_standard_filenames() { 287fn module_resolution_works_for_non_standard_filenames() {
169 let (item_map, module_id) = item_map_custom_crate_root( 288 let (item_map, module_id) = item_map_custom_crate_root(
170 " 289 "