From 76ff5b7c15b2c4e85895a49e5859e546d1d6227e Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 3 Dec 2019 19:33:48 +0800 Subject: Add tests --- crates/ra_hir_def/src/nameres/tests.rs | 32 ++++++++++++++++++++++++++++++++ crates/ra_hir_ty/src/tests/macros.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) (limited to 'crates') diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs index 87fcd617c..61cdd768e 100644 --- a/crates/ra_hir_def/src/nameres/tests.rs +++ b/crates/ra_hir_def/src/nameres/tests.rs @@ -558,3 +558,35 @@ fn cfg_test() { ⋮Foo: t v "###); } + +#[test] +fn infer_multiple_namespace() { + let map = def_map( + r#" +//- /main.rs +mod a { + pub type T = (); + pub use crate::b::*; +} + +use crate::a::T; + +mod b { + pub const T: () = (); +} +"#, + ); + + assert_snapshot!(map, @r###" + ⋮crate + ⋮T: t v + ⋮a: t + ⋮b: t + ⋮ + ⋮crate::b + ⋮T: v + ⋮ + ⋮crate::a + ⋮T: t v +"###); +} diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs index 9c29a054e..812f171db 100644 --- a/crates/ra_hir_ty/src/tests/macros.rs +++ b/crates/ra_hir_ty/src/tests/macros.rs @@ -210,6 +210,35 @@ pub fn baz() -> usize { 31usize } assert_eq!("(i32, usize)", type_at_pos(&db, pos)); } +#[test] +fn infer_type_value_non_legacy_macro_use_as() { + assert_snapshot!( + infer(r#" +mod m { + macro_rules! _foo { + ($x:ident) => { type $x = u64; } + } + pub(crate) use _foo as foo; +} + +m::foo!(foo); +use foo as bar; +fn f() -> bar { 0 } +fn main() { + let _a = f(); +} +"#), + @r###" + [159; 164) '{ 0 }': u64 + [161; 162) '0': u64 + [175; 199) '{ ...f(); }': () + [187; 189) '_a': u64 + [193; 194) 'f': fn f() -> u64 + [193; 196) 'f()': u64 + "### + ); +} + #[test] fn infer_builtin_macros_line() { assert_snapshot!( -- cgit v1.2.3