aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide_api/src/expand_macro.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/expand_macro.rs b/crates/ra_ide_api/src/expand_macro.rs
index 7f39262dc..789d6cbde 100644
--- a/crates/ra_ide_api/src/expand_macro.rs
+++ b/crates/ra_ide_api/src/expand_macro.rs
@@ -175,4 +175,47 @@ fn some_thing() -> u32 {
175} 175}
176"###); 176"###);
177 } 177 }
178
179 #[test]
180 fn macro_expand_match_ast() {
181 let res = check_expand_macro(
182 r#"
183 //- /lib.rs
184 macro_rules! match_ast {
185 (match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) };
186
187 (match ($node:expr) {
188 $( ast::$ast:ident($it:ident) => $res:block, )*
189 _ => $catch_all:expr $(,)?
190 }) => {{
191 $( if let Some($it) = ast::$ast::cast($node.clone()) $res else )*
192 { $catch_all }
193 }};
194 }
195
196 fn main() {
197 mat<|>ch_ast! {
198 match container {
199 ast::TraitDef(it) => {},
200 ast::ImplBlock(it) => {},
201 _ => { continue },
202 }
203 }
204 }
205 "#,
206 );
207
208 assert_eq!(res.name, "match_ast");
209 assert_snapshot!(res.expansion, @r###"
210{
211 if let Some(it) = ast::TraitDef::cast(container.clone()){}
212 else if let Some(it) = ast::ImplBlock::cast(container.clone()){}
213 else {
214 {
215 continue
216 }
217 }
218}
219"###);
220 }
178} 221}