aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres/tests.rs
diff options
context:
space:
mode:
authorAlexander Andreev <[email protected]>2019-07-07 14:06:54 +0100
committerAlexander Andreev <[email protected]>2019-07-07 14:06:54 +0100
commit1c582be63b35c6602638023d4bd0bc426b0ca744 (patch)
tree1dd7188a39afb8e18c1e57f522abb059bdecba92 /crates/ra_hir/src/nameres/tests.rs
parent8579a9b834555339e400f3161280305a99189a5f (diff)
Moved module resolution test in mods.rs
Diffstat (limited to 'crates/ra_hir/src/nameres/tests.rs')
-rw-r--r--crates/ra_hir/src/nameres/tests.rs192
1 files changed, 1 insertions, 191 deletions
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index 5e8ea6780..8b0887fb5 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -2,6 +2,7 @@ mod macros;
2mod globs; 2mod globs;
3mod incremental; 3mod incremental;
4mod primitives; 4mod primitives;
5mod mods;
5 6
6use std::sync::Arc; 7use std::sync::Arc;
7 8
@@ -313,178 +314,6 @@ fn edition_2015_imports() {
313} 314}
314 315
315#[test] 316#[test]
316fn module_resolution_works_for_non_standard_filenames() {
317 let map = def_map_with_crate_graph(
318 "
319 //- /my_library.rs
320 mod foo;
321 use self::foo::Bar;
322
323 //- /foo/mod.rs
324 pub struct Bar;
325 ",
326 crate_graph! {
327 "my_library": ("/my_library.rs", []),
328 },
329 );
330
331 assert_snapshot_matches!(map, @r###"
332 ⋮crate
333 ⋮Bar: t v
334 ⋮foo: t
335
336 ⋮crate::foo
337 ⋮Bar: t v
338 "###);
339}
340
341#[test]
342fn module_resolution_works_for_raw_modules() {
343 let map = def_map_with_crate_graph(
344 "
345 //- /library.rs
346 mod r#async;
347 use self::r#async::Bar;
348
349 //- /async.rs
350 pub struct Bar;
351 ",
352 crate_graph! {
353 "library": ("/library.rs", []),
354 },
355 );
356
357 assert_snapshot_matches!(map, @r###"
358 ⋮crate
359 ⋮Bar: t v
360 ⋮async: t
361
362 ⋮crate::async
363 ⋮Bar: t v
364 "###);
365}
366
367#[test]
368fn module_resolution_decl_path() {
369 let map = def_map_with_crate_graph(
370 "
371 //- /library.rs
372 #[path = \"bar/baz/foo.rs\"]
373 mod foo;
374 use self::foo::Bar;
375
376 //- /bar/baz/foo.rs
377 pub struct Bar;
378 ",
379 crate_graph! {
380 "library": ("/library.rs", []),
381 },
382 );
383
384 assert_snapshot_matches!(map, @r###"
385 ⋮crate
386 ⋮Bar: t v
387 ⋮foo: t
388
389 ⋮crate::foo
390 ⋮Bar: t v
391 "###);
392}
393
394#[test]
395fn module_resolution_module_with_path_in_mod_rs() {
396 let map = def_map_with_crate_graph(
397 "
398 //- /main.rs
399 mod foo;
400
401 //- /foo/mod.rs
402 #[path = \"baz.rs\"]
403 pub mod bar;
404
405 use self::bar::Baz;
406
407 //- /foo/baz.rs
408 pub struct Baz;
409 ",
410 crate_graph! {
411 "main": ("/main.rs", []),
412 },
413 );
414
415 assert_snapshot_matches!(map, @r###"
416 ⋮crate
417 ⋮foo: t
418
419 ⋮crate::foo
420 ⋮Baz: t v
421 ⋮bar: t
422
423 ⋮crate::foo::bar
424 ⋮Baz: t v
425 "###);
426}
427
428#[test]
429fn module_resolution_module_with_path_non_crate_root() {
430 let map = def_map_with_crate_graph(
431 "
432 //- /main.rs
433 mod foo;
434
435 //- /foo.rs
436 #[path = \"baz.rs\"]
437 pub mod bar;
438
439 use self::bar::Baz;
440
441 //- /baz.rs
442 pub struct Baz;
443 ",
444 crate_graph! {
445 "main": ("/main.rs", []),
446 },
447 );
448
449 assert_snapshot_matches!(map, @r###"
450 ⋮crate
451 ⋮foo: t
452
453 ⋮crate::foo
454 ⋮Baz: t v
455 ⋮bar: t
456
457 ⋮crate::foo::bar
458 ⋮Baz: t v
459 "###);
460}
461
462#[test]
463fn name_res_works_for_broken_modules() {
464 covers!(name_res_works_for_broken_modules);
465 let map = def_map(
466 "
467 //- /lib.rs
468 mod foo // no `;`, no body
469
470 use self::foo::Baz;
471
472 //- /foo/mod.rs
473 pub mod bar;
474
475 pub use self::bar::Baz;
476
477 //- /foo/bar.rs
478 pub struct Baz;
479 ",
480 );
481 assert_snapshot_matches!(map, @r###"
482 ⋮crate
483 ⋮Baz: _
484 "###);
485}
486
487#[test]
488fn item_map_using_self() { 317fn item_map_using_self() {
489 let map = def_map( 318 let map = def_map(
490 " 319 "
@@ -676,22 +505,3 @@ fn values_dont_shadow_extern_crates() {
676 ⋮foo: v 505 ⋮foo: v
677 "###); 506 "###);
678} 507}
679
680#[test]
681fn unresolved_module_diagnostics() {
682 let diagnostics = MockDatabase::with_files(
683 r"
684 //- /lib.rs
685 mod foo;
686 mod bar;
687 mod baz {}
688 //- /foo.rs
689 ",
690 )
691 .diagnostics();
692
693 assert_snapshot_matches!(diagnostics, @r###"
694"mod bar;": unresolved module
695"###
696 );
697}