From dfa758f6a9146fbcb5109e7294d0a8e561c77913 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Fri, 30 Aug 2019 02:01:26 +0800 Subject: Add test --- crates/ra_hir/src/nameres/tests/macros.rs | 55 ++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir/src/nameres/tests') diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs index 631df2cef..a8ee0ba28 100644 --- a/crates/ra_hir/src/nameres/tests/macros.rs +++ b/crates/ra_hir/src/nameres/tests/macros.rs @@ -99,14 +99,14 @@ fn macro_rules_from_other_crates_are_visible() { fn unexpanded_macro_should_expand_by_fixedpoint_loop() { let map = def_map_with_crate_graph( " - //- /main.rs + //- /main.rs macro_rules! baz { () => { - use foo::bar; + use foo::bar; } } - - foo!(); + + foo!(); bar!(); baz!(); @@ -114,7 +114,7 @@ fn unexpanded_macro_should_expand_by_fixedpoint_loop() { #[macro_export] macro_rules! foo { () => { - struct Foo { field: u32 } + struct Foo { field: u32 } } } #[macro_export] @@ -137,3 +137,48 @@ fn unexpanded_macro_should_expand_by_fixedpoint_loop() { ⋮foo: m "###); } + +#[test] +fn macro_rules_from_other_crates_are_visible_with_macro_use() { + let map = def_map_with_crate_graph( + " + //- /main.rs + #[macro_use] + extern crate foo; + + structs!(Foo, Bar) + + mod bar; + + //- /bar.rs + use crate::*; + + //- /lib.rs + #[macro_export] + macro_rules! structs { + ($($i:ident),*) => { + $(struct $i { field: u32 } )* + } + } + ", + crate_graph! { + "main": ("/main.rs", ["foo"]), + "foo": ("/lib.rs", []), + }, + ); + assert_snapshot!(map, @r###" + ⋮crate + ⋮Bar: t v + ⋮Foo: t v + ⋮bar: t + ⋮foo: t + ⋮structs: m + ⋮ + ⋮crate::bar + ⋮Bar: t v + ⋮Foo: t v + ⋮bar: t + ⋮foo: t + ⋮structs: m + "###); +} -- cgit v1.2.3 From a66214b34effe1ad7f4351a1b920cf3a8f98d3c0 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Mon, 2 Sep 2019 14:36:20 +0800 Subject: Fix import strategy of `macro_use` and its test --- crates/ra_hir/src/nameres/tests/macros.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'crates/ra_hir/src/nameres/tests') diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs index a8ee0ba28..cfddf3029 100644 --- a/crates/ra_hir/src/nameres/tests/macros.rs +++ b/crates/ra_hir/src/nameres/tests/macros.rs @@ -140,6 +140,7 @@ fn unexpanded_macro_should_expand_by_fixedpoint_loop() { #[test] fn macro_rules_from_other_crates_are_visible_with_macro_use() { + covers!(macro_rules_from_other_crates_are_visible_with_macro_use); let map = def_map_with_crate_graph( " //- /main.rs @@ -160,6 +161,13 @@ fn macro_rules_from_other_crates_are_visible_with_macro_use() { $(struct $i { field: u32 } )* } } + + mod priv_mod { + #[macro_export] + macro_rules! baz { + () => {}; + } + } ", crate_graph! { "main": ("/main.rs", ["foo"]), @@ -171,6 +179,7 @@ fn macro_rules_from_other_crates_are_visible_with_macro_use() { ⋮Bar: t v ⋮Foo: t v ⋮bar: t + ⋮baz: m ⋮foo: t ⋮structs: m ⋮ @@ -178,6 +187,7 @@ fn macro_rules_from_other_crates_are_visible_with_macro_use() { ⋮Bar: t v ⋮Foo: t v ⋮bar: t + ⋮baz: m ⋮foo: t ⋮structs: m "###); -- cgit v1.2.3 From 0d23286caf35a7cd8aed6e20fab3a2a3ed91ae8f Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Thu, 5 Sep 2019 11:35:13 +0800 Subject: Let `macro_use` bypass module scope --- crates/ra_hir/src/nameres/tests/macros.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'crates/ra_hir/src/nameres/tests') diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs index cfddf3029..ff762ee30 100644 --- a/crates/ra_hir/src/nameres/tests/macros.rs +++ b/crates/ra_hir/src/nameres/tests/macros.rs @@ -147,25 +147,31 @@ fn macro_rules_from_other_crates_are_visible_with_macro_use() { #[macro_use] extern crate foo; - structs!(Foo, Bar) + structs!(Foo); + structs_priv!(Bar); + structs_not_exported!(MacroNotResolved1); + crates::structs!(MacroNotResolved2); mod bar; //- /bar.rs - use crate::*; + structs!(Baz); + crates::structs!(MacroNotResolved3); //- /lib.rs #[macro_export] macro_rules! structs { - ($($i:ident),*) => { - $(struct $i { field: u32 } )* - } + ($i:ident) => { struct $i; } + } + + macro_rules! structs_not_exported { + ($i:ident) => { struct $i; } } mod priv_mod { #[macro_export] - macro_rules! baz { - () => {}; + macro_rules! structs_priv { + ($i:ident) => { struct $i; } } } ", @@ -179,16 +185,9 @@ fn macro_rules_from_other_crates_are_visible_with_macro_use() { ⋮Bar: t v ⋮Foo: t v ⋮bar: t - ⋮baz: m ⋮foo: t - ⋮structs: m ⋮ ⋮crate::bar - ⋮Bar: t v - ⋮Foo: t v - ⋮bar: t - ⋮baz: m - ⋮foo: t - ⋮structs: m + ⋮Baz: t v "###); } -- cgit v1.2.3 From 3ff5d7e73c65393672886de09738adf49cdd4984 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Thu, 5 Sep 2019 12:03:32 +0800 Subject: Fix typo --- crates/ra_hir/src/nameres/tests/macros.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir/src/nameres/tests') diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs index ff762ee30..ebfefe273 100644 --- a/crates/ra_hir/src/nameres/tests/macros.rs +++ b/crates/ra_hir/src/nameres/tests/macros.rs @@ -150,13 +150,13 @@ fn macro_rules_from_other_crates_are_visible_with_macro_use() { structs!(Foo); structs_priv!(Bar); structs_not_exported!(MacroNotResolved1); - crates::structs!(MacroNotResolved2); + crate::structs!(MacroNotResolved2); mod bar; //- /bar.rs structs!(Baz); - crates::structs!(MacroNotResolved3); + crate::structs!(MacroNotResolved3); //- /lib.rs #[macro_export] -- cgit v1.2.3