aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres/tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/nameres/tests')
-rw-r--r--crates/ra_hir/src/nameres/tests/macros.rs121
-rw-r--r--crates/ra_hir/src/nameres/tests/mod_resolution.rs (renamed from crates/ra_hir/src/nameres/tests/mods.rs)0
2 files changed, 116 insertions, 5 deletions
diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs
index 631df2cef..aece1515b 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() {
99fn unexpanded_macro_should_expand_by_fixedpoint_loop() { 99fn unexpanded_macro_should_expand_by_fixedpoint_loop() {
100 let map = def_map_with_crate_graph( 100 let map = def_map_with_crate_graph(
101 " 101 "
102 //- /main.rs 102 //- /main.rs
103 macro_rules! baz { 103 macro_rules! baz {
104 () => { 104 () => {
105 use foo::bar; 105 use foo::bar;
106 } 106 }
107 } 107 }
108 108
109 foo!(); 109 foo!();
110 bar!(); 110 bar!();
111 baz!(); 111 baz!();
112 112
@@ -114,7 +114,7 @@ fn unexpanded_macro_should_expand_by_fixedpoint_loop() {
114 #[macro_export] 114 #[macro_export]
115 macro_rules! foo { 115 macro_rules! foo {
116 () => { 116 () => {
117 struct Foo { field: u32 } 117 struct Foo { field: u32 }
118 } 118 }
119 } 119 }
120 #[macro_export] 120 #[macro_export]
@@ -137,3 +137,114 @@ fn unexpanded_macro_should_expand_by_fixedpoint_loop() {
137 ⋮foo: m 137 ⋮foo: m
138 "###); 138 "###);
139} 139}
140
141#[test]
142fn macro_rules_from_other_crates_are_visible_with_macro_use() {
143 covers!(macro_rules_from_other_crates_are_visible_with_macro_use);
144 let map = def_map_with_crate_graph(
145 "
146 //- /main.rs
147 structs!(Foo);
148 structs_priv!(Bar);
149 structs_not_exported!(MacroNotResolved1);
150 crate::structs!(MacroNotResolved2);
151
152 mod bar;
153
154 #[macro_use]
155 extern crate foo;
156
157 //- /bar.rs
158 structs!(Baz);
159 crate::structs!(MacroNotResolved3);
160
161 //- /lib.rs
162 #[macro_export]
163 macro_rules! structs {
164 ($i:ident) => { struct $i; }
165 }
166
167 macro_rules! structs_not_exported {
168 ($i:ident) => { struct $i; }
169 }
170
171 mod priv_mod {
172 #[macro_export]
173 macro_rules! structs_priv {
174 ($i:ident) => { struct $i; }
175 }
176 }
177 ",
178 crate_graph! {
179 "main": ("/main.rs", ["foo"]),
180 "foo": ("/lib.rs", []),
181 },
182 );
183 assert_snapshot!(map, @r###"
184 ⋮crate
185 ⋮Bar: t v
186 ⋮Foo: t v
187 ⋮bar: t
188 ⋮foo: t
189
190 ⋮crate::bar
191 ⋮Baz: t v
192 "###);
193}
194
195#[test]
196fn prelude_is_macro_use() {
197 covers!(prelude_is_macro_use);
198 let map = def_map_with_crate_graph(
199 "
200 //- /main.rs
201 structs!(Foo);
202 structs_priv!(Bar);
203 structs_outside!(Out);
204 crate::structs!(MacroNotResolved2);
205
206 mod bar;
207
208 //- /bar.rs
209 structs!(Baz);
210 crate::structs!(MacroNotResolved3);
211
212 //- /lib.rs
213 #[prelude_import]
214 use self::prelude::*;
215
216 mod prelude {
217 #[macro_export]
218 macro_rules! structs {
219 ($i:ident) => { struct $i; }
220 }
221
222 mod priv_mod {
223 #[macro_export]
224 macro_rules! structs_priv {
225 ($i:ident) => { struct $i; }
226 }
227 }
228 }
229
230 #[macro_export]
231 macro_rules! structs_outside {
232 ($i:ident) => { struct $i; }
233 }
234 ",
235 crate_graph! {
236 "main": ("/main.rs", ["foo"]),
237 "foo": ("/lib.rs", []),
238 },
239 );
240 assert_snapshot!(map, @r###"
241 ⋮crate
242 ⋮Bar: t v
243 ⋮Foo: t v
244 ⋮Out: t v
245 ⋮bar: t
246
247 ⋮crate::bar
248 ⋮Baz: t v
249 "###);
250}
diff --git a/crates/ra_hir/src/nameres/tests/mods.rs b/crates/ra_hir/src/nameres/tests/mod_resolution.rs
index 4f8398460..4f8398460 100644
--- a/crates/ra_hir/src/nameres/tests/mods.rs
+++ b/crates/ra_hir/src/nameres/tests/mod_resolution.rs