From b28c54a2c239acd73f2eea80fda9ee3960d2c046 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 16:28:27 +0200 Subject: Rename ra_hir_def -> hir_def --- crates/ra_hir_def/src/nameres/tests/globs.rs | 338 --------- crates/ra_hir_def/src/nameres/tests/incremental.rs | 101 --- crates/ra_hir_def/src/nameres/tests/macros.rs | 669 ----------------- .../ra_hir_def/src/nameres/tests/mod_resolution.rs | 796 --------------------- crates/ra_hir_def/src/nameres/tests/primitives.rs | 23 - 5 files changed, 1927 deletions(-) delete mode 100644 crates/ra_hir_def/src/nameres/tests/globs.rs delete mode 100644 crates/ra_hir_def/src/nameres/tests/incremental.rs delete mode 100644 crates/ra_hir_def/src/nameres/tests/macros.rs delete mode 100644 crates/ra_hir_def/src/nameres/tests/mod_resolution.rs delete mode 100644 crates/ra_hir_def/src/nameres/tests/primitives.rs (limited to 'crates/ra_hir_def/src/nameres/tests') diff --git a/crates/ra_hir_def/src/nameres/tests/globs.rs b/crates/ra_hir_def/src/nameres/tests/globs.rs deleted file mode 100644 index 2ae836e3c..000000000 --- a/crates/ra_hir_def/src/nameres/tests/globs.rs +++ /dev/null @@ -1,338 +0,0 @@ -use super::*; - -#[test] -fn glob_1() { - check( - r#" -//- /lib.rs -mod foo; -use foo::*; - -//- /foo/mod.rs -pub mod bar; -pub use self::bar::Baz; -pub struct Foo; - -//- /foo/bar.rs -pub struct Baz; -"#, - expect![[r#" - crate - Baz: t v - Foo: t v - bar: t - foo: t - - crate::foo - Baz: t v - Foo: t v - bar: t - - crate::foo::bar - Baz: t v - "#]], - ); -} - -#[test] -fn glob_2() { - check( - r#" -//- /lib.rs -mod foo; -use foo::*; - -//- /foo/mod.rs -pub mod bar; -pub use self::bar::*; -pub struct Foo; - -//- /foo/bar.rs -pub struct Baz; -pub use super::*; -"#, - expect![[r#" - crate - Baz: t v - Foo: t v - bar: t - foo: t - - crate::foo - Baz: t v - Foo: t v - bar: t - - crate::foo::bar - Baz: t v - Foo: t v - bar: t - "#]], - ); -} - -#[test] -fn glob_privacy_1() { - check( - r" -//- /lib.rs -mod foo; -use foo::*; - -//- /foo/mod.rs -pub mod bar; -pub use self::bar::*; -struct PrivateStructFoo; - -//- /foo/bar.rs -pub struct Baz; -struct PrivateStructBar; -pub use super::*; -", - expect![[r#" - crate - Baz: t v - bar: t - foo: t - - crate::foo - Baz: t v - PrivateStructFoo: t v - bar: t - - crate::foo::bar - Baz: t v - PrivateStructBar: t v - PrivateStructFoo: t v - bar: t - "#]], - ); -} - -#[test] -fn glob_privacy_2() { - check( - r" -//- /lib.rs -mod foo; -use foo::*; -use foo::bar::*; - -//- /foo/mod.rs -mod bar; -fn Foo() {}; -pub struct Foo {}; - -//- /foo/bar.rs -pub(super) struct PrivateBaz; -struct PrivateBar; -pub(crate) struct PubCrateStruct; -", - expect![[r#" - crate - Foo: t - PubCrateStruct: t v - foo: t - - crate::foo - Foo: t v - bar: t - - crate::foo::bar - PrivateBar: t v - PrivateBaz: t v - PubCrateStruct: t v - "#]], - ); -} - -#[test] -fn glob_across_crates() { - mark::check!(glob_across_crates); - check( - r#" -//- /main.rs crate:main deps:test_crate -use test_crate::*; - -//- /lib.rs crate:test_crate -pub struct Baz; -"#, - expect![[r#" - crate - Baz: t v - "#]], - ); -} - -#[test] -fn glob_privacy_across_crates() { - check( - r#" -//- /main.rs crate:main deps:test_crate -use test_crate::*; - -//- /lib.rs crate:test_crate -pub struct Baz; -struct Foo; -"#, - expect![[r#" - crate - Baz: t v - "#]], - ); -} - -#[test] -fn glob_enum() { - mark::check!(glob_enum); - check( - r#" -enum Foo { Bar, Baz } -use self::Foo::*; -"#, - expect![[r#" - crate - Bar: t v - Baz: t v - Foo: t - "#]], - ); -} - -#[test] -fn glob_enum_group() { - mark::check!(glob_enum_group); - check( - r#" -enum Foo { Bar, Baz } -use self::Foo::{*}; -"#, - expect![[r#" - crate - Bar: t v - Baz: t v - Foo: t - "#]], - ); -} - -#[test] -fn glob_shadowed_def() { - mark::check!(import_shadowed); - check( - r#" -//- /lib.rs -mod foo; -mod bar; -use foo::*; -use bar::baz; -use baz::Bar; - -//- /foo.rs -pub mod baz { pub struct Foo; } - -//- /bar.rs -pub mod baz { pub struct Bar; } -"#, - expect![[r#" - crate - Bar: t v - bar: t - baz: t - foo: t - - crate::bar - baz: t - - crate::bar::baz - Bar: t v - - crate::foo - baz: t - - crate::foo::baz - Foo: t v - "#]], - ); -} - -#[test] -fn glob_shadowed_def_reversed() { - check( - r#" -//- /lib.rs -mod foo; -mod bar; -use bar::baz; -use foo::*; -use baz::Bar; - -//- /foo.rs -pub mod baz { pub struct Foo; } - -//- /bar.rs -pub mod baz { pub struct Bar; } -"#, - expect![[r#" - crate - Bar: t v - bar: t - baz: t - foo: t - - crate::bar - baz: t - - crate::bar::baz - Bar: t v - - crate::foo - baz: t - - crate::foo::baz - Foo: t v - "#]], - ); -} - -#[test] -fn glob_shadowed_def_dependencies() { - check( - r#" -mod a { pub mod foo { pub struct X; } } -mod b { pub use super::a::foo; } -mod c { pub mod foo { pub struct Y; } } -mod d { - use super::c::foo; - use super::b::*; - use foo::Y; -} -"#, - expect![[r#" - crate - a: t - b: t - c: t - d: t - - crate::d - Y: t v - foo: t - - crate::c - foo: t - - crate::c::foo - Y: t v - - crate::b - foo: t - - crate::a - foo: t - - crate::a::foo - X: t v - "#]], - ); -} diff --git a/crates/ra_hir_def/src/nameres/tests/incremental.rs b/crates/ra_hir_def/src/nameres/tests/incremental.rs deleted file mode 100644 index cfbc62cc4..000000000 --- a/crates/ra_hir_def/src/nameres/tests/incremental.rs +++ /dev/null @@ -1,101 +0,0 @@ -use std::sync::Arc; - -use base_db::SourceDatabaseExt; - -use super::*; - -fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change: &str) { - let (mut db, pos) = TestDB::with_position(ra_fixture_initial); - let krate = db.test_crate(); - { - let events = db.log_executed(|| { - db.crate_def_map(krate); - }); - assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) - } - db.set_file_text(pos.file_id, Arc::new(ra_fixture_change.to_string())); - - { - let events = db.log_executed(|| { - db.crate_def_map(krate); - }); - assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) - } -} - -#[test] -fn typing_inside_a_function_should_not_invalidate_def_map() { - check_def_map_is_not_recomputed( - r" - //- /lib.rs - mod foo;<|> - - use crate::foo::bar::Baz; - - enum E { A, B } - use E::*; - - fn foo() -> i32 { - 1 + 1 - } - //- /foo/mod.rs - pub mod bar; - - //- /foo/bar.rs - pub struct Baz; - ", - r" - mod foo; - - use crate::foo::bar::Baz; - - enum E { A, B } - use E::*; - - fn foo() -> i32 { 92 } - ", - ); -} - -#[test] -fn typing_inside_a_macro_should_not_invalidate_def_map() { - let (mut db, pos) = TestDB::with_position( - r" - //- /lib.rs - macro_rules! m { - ($ident:ident) => { - fn f() { - $ident + $ident; - }; - } - } - mod foo; - - //- /foo/mod.rs - pub mod bar; - - //- /foo/bar.rs - <|> - m!(X); - ", - ); - let krate = db.test_crate(); - { - let events = db.log_executed(|| { - let crate_def_map = db.crate_def_map(krate); - let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); - assert_eq!(module_data.scope.resolutions().count(), 1); - }); - assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) - } - db.set_file_text(pos.file_id, Arc::new("m!(Y);".to_string())); - - { - let events = db.log_executed(|| { - let crate_def_map = db.crate_def_map(krate); - let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); - assert_eq!(module_data.scope.resolutions().count(), 1); - }); - assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) - } -} diff --git a/crates/ra_hir_def/src/nameres/tests/macros.rs b/crates/ra_hir_def/src/nameres/tests/macros.rs deleted file mode 100644 index e0fb8bdef..000000000 --- a/crates/ra_hir_def/src/nameres/tests/macros.rs +++ /dev/null @@ -1,669 +0,0 @@ -use super::*; - -#[test] -fn macro_rules_are_globally_visible() { - check( - r#" -//- /lib.rs -macro_rules! structs { - ($($i:ident),*) => { - $(struct $i { field: u32 } )* - } -} -structs!(Foo); -mod nested; - -//- /nested.rs -structs!(Bar, Baz); -"#, - expect![[r#" - crate - Foo: t - nested: t - - crate::nested - Bar: t - Baz: t - "#]], - ); -} - -#[test] -fn macro_rules_can_define_modules() { - check( - r#" -//- /lib.rs -macro_rules! m { - ($name:ident) => { mod $name; } -} -m!(n1); -mod m { m!(n3) } - -//- /n1.rs -m!(n2) -//- /n1/n2.rs -struct X; -//- /m/n3.rs -struct Y; -"#, - expect![[r#" - crate - m: t - n1: t - - crate::m - n3: t - - crate::m::n3 - Y: t v - - crate::n1 - n2: t - - crate::n1::n2 - X: t v - "#]], - ); -} - -#[test] -fn macro_rules_from_other_crates_are_visible() { - check( - r#" -//- /main.rs crate:main deps:foo -foo::structs!(Foo, Bar) -mod bar; - -//- /bar.rs -use crate::*; - -//- /lib.rs crate:foo -#[macro_export] -macro_rules! structs { - ($($i:ident),*) => { - $(struct $i { field: u32 } )* - } -} -"#, - expect![[r#" - crate - Bar: t - Foo: t - bar: t - - crate::bar - Bar: t - Foo: t - bar: t - "#]], - ); -} - -#[test] -fn macro_rules_export_with_local_inner_macros_are_visible() { - check( - r#" -//- /main.rs crate:main deps:foo -foo::structs!(Foo, Bar) -mod bar; - -//- /bar.rs -use crate::*; - -//- /lib.rs crate:foo -#[macro_export(local_inner_macros)] -macro_rules! structs { - ($($i:ident),*) => { - $(struct $i { field: u32 } )* - } -} -"#, - expect![[r#" - crate - Bar: t - Foo: t - bar: t - - crate::bar - Bar: t - Foo: t - bar: t - "#]], - ); -} - -#[test] -fn local_inner_macros_makes_local_macros_usable() { - check( - r#" -//- /main.rs crate:main deps:foo -foo::structs!(Foo, Bar); -mod bar; - -//- /bar.rs -use crate::*; - -//- /lib.rs crate:foo -#[macro_export(local_inner_macros)] -macro_rules! structs { - ($($i:ident),*) => { - inner!($($i),*); - } -} -#[macro_export] -macro_rules! inner { - ($($i:ident),*) => { - $(struct $i { field: u32 } )* - } -} -"#, - expect![[r#" - crate - Bar: t - Foo: t - bar: t - - crate::bar - Bar: t - Foo: t - bar: t - "#]], - ); -} - -#[test] -fn unexpanded_macro_should_expand_by_fixedpoint_loop() { - check( - r#" -//- /main.rs crate:main deps:foo -macro_rules! baz { - () => { - use foo::bar; - } -} -foo!(); -bar!(); -baz!(); - -//- /lib.rs crate:foo -#[macro_export] -macro_rules! foo { - () => { - struct Foo { field: u32 } - } -} -#[macro_export] -macro_rules! bar { - () => { - use foo::foo; - } -} -"#, - expect![[r#" - crate - Foo: t - bar: m - foo: m - "#]], - ); -} - -#[test] -fn macro_rules_from_other_crates_are_visible_with_macro_use() { - mark::check!(macro_rules_from_other_crates_are_visible_with_macro_use); - check( - r#" -//- /main.rs crate:main deps:foo -structs!(Foo); -structs_priv!(Bar); -structs_not_exported!(MacroNotResolved1); -crate::structs!(MacroNotResolved2); - -mod bar; - -#[macro_use] -extern crate foo; - -//- /bar.rs -structs!(Baz); -crate::structs!(MacroNotResolved3); - -//- /lib.rs crate:foo -#[macro_export] -macro_rules! structs { - ($i:ident) => { struct $i; } -} - -macro_rules! structs_not_exported { - ($i:ident) => { struct $i; } -} - -mod priv_mod { - #[macro_export] - macro_rules! structs_priv { - ($i:ident) => { struct $i; } - } -} -"#, - expect![[r#" - crate - Bar: t v - Foo: t v - bar: t - foo: t - - crate::bar - Baz: t v - "#]], - ); -} - -#[test] -fn prelude_is_macro_use() { - mark::check!(prelude_is_macro_use); - check( - r#" -//- /main.rs crate:main deps:foo -structs!(Foo); -structs_priv!(Bar); -structs_outside!(Out); -crate::structs!(MacroNotResolved2); - -mod bar; - -//- /bar.rs -structs!(Baz); -crate::structs!(MacroNotResolved3); - -//- /lib.rs crate:foo -#[prelude_import] -use self::prelude::*; - -mod prelude { - #[macro_export] - macro_rules! structs { - ($i:ident) => { struct $i; } - } - - mod priv_mod { - #[macro_export] - macro_rules! structs_priv { - ($i:ident) => { struct $i; } - } - } -} - -#[macro_export] -macro_rules! structs_outside { - ($i:ident) => { struct $i; } -} -"#, - expect![[r#" - crate - Bar: t v - Foo: t v - Out: t v - bar: t - - crate::bar - Baz: t v - "#]], - ); -} - -#[test] -fn prelude_cycle() { - check( - r#" -#[prelude_import] -use self::prelude::*; - -declare_mod!(); - -mod prelude { - macro_rules! declare_mod { - () => (mod foo {}) - } -} -"#, - expect![[r#" - crate - prelude: t - - crate::prelude - "#]], - ); -} - -#[test] -fn plain_macros_are_legacy_textual_scoped() { - check( - r#" -//- /main.rs -mod m1; -bar!(NotFoundNotMacroUse); - -mod m2 { foo!(NotFoundBeforeInside2); } - -macro_rules! foo { - ($x:ident) => { struct $x; } -} -foo!(Ok); - -mod m3; -foo!(OkShadowStop); -bar!(NotFoundMacroUseStop); - -#[macro_use] -mod m5 { - #[macro_use] - mod m6 { - macro_rules! foo { - ($x:ident) => { fn $x() {} } - } - } -} -foo!(ok_double_macro_use_shadow); - -baz!(NotFoundBefore); -#[macro_use] -mod m7 { - macro_rules! baz { - ($x:ident) => { struct $x; } - } -} -baz!(OkAfter); - -//- /m1.rs -foo!(NotFoundBeforeInside1); -macro_rules! bar { - ($x:ident) => { struct $x; } -} - -//- /m3/mod.rs -foo!(OkAfterInside); -macro_rules! foo { - ($x:ident) => { fn $x() {} } -} -foo!(ok_shadow); - -#[macro_use] -mod m4; -bar!(OkMacroUse); - -//- /m3/m4.rs -foo!(ok_shadow_deep); -macro_rules! bar { - ($x:ident) => { struct $x; } -} -"#, - expect![[r#" - crate - Ok: t v - OkAfter: t v - OkShadowStop: t v - m1: t - m2: t - m3: t - m5: t - m7: t - ok_double_macro_use_shadow: v - - crate::m7 - - crate::m1 - - crate::m5 - m6: t - - crate::m5::m6 - - crate::m2 - - crate::m3 - OkAfterInside: t v - OkMacroUse: t v - m4: t - ok_shadow: v - - crate::m3::m4 - ok_shadow_deep: v - "#]], - ); -} - -#[test] -fn type_value_macro_live_in_different_scopes() { - check( - r#" -#[macro_export] -macro_rules! foo { - ($x:ident) => { type $x = (); } -} - -foo!(foo); -use foo as bar; - -use self::foo as baz; -fn baz() {} -"#, - expect![[r#" - crate - bar: t m - baz: t v m - foo: t m - "#]], - ); -} - -#[test] -fn macro_use_can_be_aliased() { - check( - r#" -//- /main.rs crate:main deps:foo -#[macro_use] -extern crate foo; - -foo!(Direct); -bar!(Alias); - -//- /lib.rs crate:foo -use crate::foo as bar; - -mod m { - #[macro_export] - macro_rules! foo { - ($x:ident) => { struct $x; } - } -} -"#, - expect![[r#" - crate - Alias: t v - Direct: t v - foo: t - "#]], - ); -} - -#[test] -fn path_qualified_macros() { - check( - r#" -macro_rules! foo { - ($x:ident) => { struct $x; } -} - -crate::foo!(NotResolved); - -crate::bar!(OkCrate); -bar!(OkPlain); -alias1!(NotHere); -m::alias1!(OkAliasPlain); -m::alias2!(OkAliasSuper); -m::alias3!(OkAliasCrate); -not_found!(NotFound); - -mod m { - #[macro_export] - macro_rules! bar { - ($x:ident) => { struct $x; } - } - pub use bar as alias1; - pub use super::bar as alias2; - pub use crate::bar as alias3; - pub use self::bar as not_found; -} -"#, - expect![[r#" - crate - OkAliasCrate: t v - OkAliasPlain: t v - OkAliasSuper: t v - OkCrate: t v - OkPlain: t v - bar: m - m: t - - crate::m - alias1: m - alias2: m - alias3: m - not_found: _ - "#]], - ); -} - -#[test] -fn macro_dollar_crate_is_correct_in_item() { - mark::check!(macro_dollar_crate_self); - check( - r#" -//- /main.rs crate:main deps:foo -#[macro_use] -extern crate foo; - -#[macro_use] -mod m { - macro_rules! current { - () => { - use $crate::Foo as FooSelf; - } - } -} - -struct Foo; - -current!(); -not_current1!(); -foo::not_current2!(); - -//- /lib.rs crate:foo -mod m { - #[macro_export] - macro_rules! not_current1 { - () => { - use $crate::Bar; - } - } -} - -#[macro_export] -macro_rules! not_current2 { - () => { - use $crate::Baz; - } -} - -struct Bar; -struct Baz; -"#, - expect![[r#" - crate - Bar: t v - Baz: t v - Foo: t v - FooSelf: t v - foo: t - m: t - - crate::m - "#]], - ); -} - -#[test] -fn macro_dollar_crate_is_correct_in_indirect_deps() { - mark::check!(macro_dollar_crate_other); - // From std - check( - r#" -//- /main.rs crate:main deps:std -foo!(); - -//- /std.rs crate:std deps:core -#[prelude_import] -use self::prelude::*; - -pub use core::foo; - -mod prelude {} - -#[macro_use] -mod std_macros; - -//- /core.rs crate:core -#[macro_export] -macro_rules! foo { - () => { - use $crate::bar; - } -} - -pub struct bar; -"#, - expect![[r#" - crate - bar: t v - "#]], - ); -} - -#[test] -fn expand_derive() { - let map = compute_crate_def_map( - " - //- /main.rs - #[derive(Copy, Clone)] - struct Foo; - ", - ); - assert_eq!(map.modules[map.root].scope.impls().len(), 2); -} - -#[test] -fn macro_expansion_overflow() { - mark::check!(macro_expansion_overflow); - check( - r#" -macro_rules! a { - ($e:expr; $($t:tt)*) => { - b!($($t)*); - }; - () => {}; -} - -macro_rules! b { - (static = $e:expr; $($t:tt)*) => { - a!($e; $($t)*); - }; - () => {}; -} - -b! { static = #[] (); } -"#, - expect![[r#" - crate - "#]], - ); -} diff --git a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs deleted file mode 100644 index 1f619787e..000000000 --- a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs +++ /dev/null @@ -1,796 +0,0 @@ -use super::*; - -#[test] -fn name_res_works_for_broken_modules() { - mark::check!(name_res_works_for_broken_modules); - check( - r" -//- /lib.rs -mod foo // no `;`, no body -use self::foo::Baz; - -//- /foo/mod.rs -pub mod bar; -pub use self::bar::Baz; - -//- /foo/bar.rs -pub struct Baz; -", - expect![[r#" - crate - Baz: _ - foo: t - - crate::foo - "#]], - ); -} - -#[test] -fn nested_module_resolution() { - check( - r#" -//- /lib.rs -mod n1; - -//- /n1.rs -mod n2; - -//- /n1/n2.rs -struct X; -"#, - expect![[r#" - crate - n1: t - - crate::n1 - n2: t - - crate::n1::n2 - X: t v - "#]], - ); -} - -#[test] -fn nested_module_resolution_2() { - check( - r#" -//- /lib.rs -mod prelude; -mod iter; - -//- /prelude.rs -pub use crate::iter::Iterator; - -//- /iter.rs -pub use self::traits::Iterator; -mod traits; - -//- /iter/traits.rs -pub use self::iterator::Iterator; -mod iterator; - -//- /iter/traits/iterator.rs -pub trait Iterator; -"#, - expect![[r#" - crate - iter: t - prelude: t - - crate::iter - Iterator: t - traits: t - - crate::iter::traits - Iterator: t - iterator: t - - crate::iter::traits::iterator - Iterator: t - - crate::prelude - Iterator: t - "#]], - ); -} - -#[test] -fn module_resolution_works_for_non_standard_filenames() { - check( - r#" -//- /my_library.rs crate:my_library -mod foo; -use self::foo::Bar; - -//- /foo/mod.rs -pub struct Bar; -"#, - expect![[r#" - crate - Bar: t v - foo: t - - crate::foo - Bar: t v - "#]], - ); -} - -#[test] -fn module_resolution_works_for_raw_modules() { - check( - r#" -//- /lib.rs -mod r#async; -use self::r#async::Bar; - -//- /async.rs -pub struct Bar; -"#, - expect![[r#" - crate - Bar: t v - async: t - - crate::async - Bar: t v - "#]], - ); -} - -#[test] -fn module_resolution_decl_path() { - check( - r#" -//- /lib.rs -#[path = "bar/baz/foo.rs"] -mod foo; -use self::foo::Bar; - -//- /bar/baz/foo.rs -pub struct Bar; -"#, - expect![[r#" - crate - Bar: t v - foo: t - - crate::foo - Bar: t v - "#]], - ); -} - -#[test] -fn module_resolution_module_with_path_in_mod_rs() { - check( - r#" -//- /main.rs -mod foo; - -//- /foo/mod.rs -#[path = "baz.rs"] -pub mod bar; -use self::bar::Baz; - -//- /foo/baz.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - Baz: t v - bar: t - - crate::foo::bar - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_module_with_path_non_crate_root() { - check( - r#" -//- /main.rs -mod foo; - -//- /foo.rs -#[path = "baz.rs"] -pub mod bar; -use self::bar::Baz; - -//- /baz.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - Baz: t v - bar: t - - crate::foo::bar - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_module_decl_path_super() { - check( - r#" -//- /main.rs -#[path = "bar/baz/module.rs"] -mod foo; -pub struct Baz; - -//- /bar/baz/module.rs -use super::Baz; -"#, - expect![[r#" - crate - Baz: t v - foo: t - - crate::foo - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_explicit_path_mod_rs() { - check( - r#" -//- /main.rs -#[path = "module/mod.rs"] -mod foo; - -//- /module/mod.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_relative_path() { - check( - r#" -//- /main.rs -mod foo; - -//- /foo.rs -#[path = "./sub.rs"] -pub mod foo_bar; - -//- /sub.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - foo_bar: t - - crate::foo::foo_bar - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_relative_path_2() { - check( - r#" -//- /main.rs -mod foo; - -//- /foo/mod.rs -#[path="../sub.rs"] -pub mod foo_bar; - -//- /sub.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - foo_bar: t - - crate::foo::foo_bar - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_relative_path_outside_root() { - check( - r#" -//- /main.rs -#[path="../../../../../outside.rs"] -mod foo; -"#, - expect![[r#" - crate - "#]], - ); -} - -#[test] -fn module_resolution_explicit_path_mod_rs_2() { - check( - r#" -//- /main.rs -#[path = "module/bar/mod.rs"] -mod foo; - -//- /module/bar/mod.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_explicit_path_mod_rs_with_win_separator() { - check( - r#" -//- /main.rs -#[path = "module\bar\mod.rs"] -mod foo; - -//- /module/bar/mod.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_decl_inside_inline_module_with_path_attribute() { - check( - r#" -//- /main.rs -#[path = "models"] -mod foo { mod bar; } - -//- /models/bar.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - bar: t - - crate::foo::bar - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_decl_inside_inline_module() { - check( - r#" -//- /main.rs -mod foo { mod bar; } - -//- /foo/bar.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - bar: t - - crate::foo::bar - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_decl_inside_inline_module_2_with_path_attribute() { - check( - r#" -//- /main.rs -#[path = "models/db"] -mod foo { mod bar; } - -//- /models/db/bar.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - bar: t - - crate::foo::bar - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_decl_inside_inline_module_3() { - check( - r#" -//- /main.rs -#[path = "models/db"] -mod foo { - #[path = "users.rs"] - mod bar; -} - -//- /models/db/users.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - bar: t - - crate::foo::bar - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_decl_inside_inline_module_empty_path() { - check( - r#" -//- /main.rs -#[path = ""] -mod foo { - #[path = "users.rs"] - mod bar; -} - -//- /users.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - bar: t - - crate::foo::bar - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_decl_empty_path() { - check( - r#" -//- /main.rs -#[path = ""] // Should try to read `/` (a directory) -mod foo; - -//- /foo.rs -pub struct Baz; -"#, - expect![[r#" - crate - "#]], - ); -} - -#[test] -fn module_resolution_decl_inside_inline_module_relative_path() { - check( - r#" -//- /main.rs -#[path = "./models"] -mod foo { mod bar; } - -//- /models/bar.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - bar: t - - crate::foo::bar - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_decl_inside_inline_module_in_crate_root() { - check( - r#" -//- /main.rs -mod foo { - #[path = "baz.rs"] - mod bar; -} -use self::foo::bar::Baz; - -//- /foo/baz.rs -pub struct Baz; -"#, - expect![[r#" - crate - Baz: t v - foo: t - - crate::foo - bar: t - - crate::foo::bar - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_decl_inside_inline_module_in_mod_rs() { - check( - r#" -//- /main.rs -mod foo; - -//- /foo/mod.rs -mod bar { - #[path = "qwe.rs"] - pub mod baz; -} -use self::bar::baz::Baz; - -//- /foo/bar/qwe.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - Baz: t v - bar: t - - crate::foo::bar - baz: t - - crate::foo::bar::baz - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_decl_inside_inline_module_in_non_crate_root() { - check( - r#" -//- /main.rs -mod foo; - -//- /foo.rs -mod bar { - #[path = "qwe.rs"] - pub mod baz; -} -use self::bar::baz::Baz; - -//- /foo/bar/qwe.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - Baz: t v - bar: t - - crate::foo::bar - baz: t - - crate::foo::bar::baz - Baz: t v - "#]], - ); -} - -#[test] -fn module_resolution_decl_inside_inline_module_in_non_crate_root_2() { - check( - r#" -//- /main.rs -mod foo; - -//- /foo.rs -#[path = "bar"] -mod bar { - pub mod baz; -} -use self::bar::baz::Baz; - -//- /bar/baz.rs -pub struct Baz; -"#, - expect![[r#" - crate - foo: t - - crate::foo - Baz: t v - bar: t - - crate::foo::bar - baz: t - - crate::foo::bar::baz - Baz: t v - "#]], - ); -} - -#[test] -fn unresolved_module_diagnostics() { - let db = TestDB::with_files( - r" - //- /lib.rs - mod foo; - mod bar; - mod baz {} - //- /foo.rs - ", - ); - let krate = db.test_crate(); - - let crate_def_map = db.crate_def_map(krate); - - expect![[r#" - [ - UnresolvedModule { - module: Idx::(0), - declaration: InFile { - file_id: HirFileId( - FileId( - FileId( - 0, - ), - ), - ), - value: FileAstId::(1), - }, - candidate: "bar.rs", - }, - ] - "#]] - .assert_debug_eq(&crate_def_map.diagnostics); -} - -#[test] -fn module_resolution_decl_inside_module_in_non_crate_root_2() { - check( - r#" -//- /main.rs -#[path="module/m2.rs"] -mod module; - -//- /module/m2.rs -pub mod submod; - -//- /module/submod.rs -pub struct Baz; -"#, - expect![[r#" - crate - module: t - - crate::module - submod: t - - crate::module::submod - Baz: t v - "#]], - ); -} - -#[test] -fn nested_out_of_line_module() { - check( - r#" -//- /lib.rs -mod a { - mod b { - mod c; - } -} - -//- /a/b/c.rs -struct X; -"#, - expect![[r#" - crate - a: t - - crate::a - b: t - - crate::a::b - c: t - - crate::a::b::c - X: t v - "#]], - ); -} - -#[test] -fn nested_out_of_line_module_with_path() { - check( - r#" -//- /lib.rs -mod a { - #[path = "d/e"] - mod b { - mod c; - } -} - -//- /a/d/e/c.rs -struct X; -"#, - expect![[r#" - crate - a: t - - crate::a - b: t - - crate::a::b - c: t - - crate::a::b::c - X: t v - "#]], - ); -} diff --git a/crates/ra_hir_def/src/nameres/tests/primitives.rs b/crates/ra_hir_def/src/nameres/tests/primitives.rs deleted file mode 100644 index 215e8952d..000000000 --- a/crates/ra_hir_def/src/nameres/tests/primitives.rs +++ /dev/null @@ -1,23 +0,0 @@ -use super::*; - -#[test] -fn primitive_reexport() { - check( - r#" -//- /lib.rs -mod foo; -use foo::int; - -//- /foo.rs -pub use i32 as int; -"#, - expect![[r#" - crate - foo: t - int: t - - crate::foo - int: t - "#]], - ); -} -- cgit v1.2.3