diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/macros.rs | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/crates/ra_hir/src/macros.rs b/crates/ra_hir/src/macros.rs index 7e9aba3f2..059543bf2 100644 --- a/crates/ra_hir/src/macros.rs +++ b/crates/ra_hir/src/macros.rs | |||
@@ -254,7 +254,7 @@ fn convert_tt(tt: &SyntaxNode) -> Option<tt::Subtree> { | |||
254 | 254 | ||
255 | #[test] | 255 | #[test] |
256 | fn test_convert_tt() { | 256 | fn test_convert_tt() { |
257 | let text = r#" | 257 | let macro_defenition = r#" |
258 | macro_rules! impl_froms { | 258 | macro_rules! impl_froms { |
259 | ($e:ident: $($v:ident),*) => { | 259 | ($e:ident: $($v:ident),*) => { |
260 | $( | 260 | $( |
@@ -267,13 +267,32 @@ macro_rules! impl_froms { | |||
267 | } | 267 | } |
268 | } | 268 | } |
269 | "#; | 269 | "#; |
270 | let source_file = ast::SourceFile::parse(text); | 270 | |
271 | let maco_call = source_file | 271 | let macro_invocation = r#" |
272 | impl_froms!(TokenTree: Leaf, Subtree); | ||
273 | "#; | ||
274 | |||
275 | let source_file = ast::SourceFile::parse(macro_defenition); | ||
276 | let macro_defenition = source_file | ||
272 | .syntax() | 277 | .syntax() |
273 | .descendants() | 278 | .descendants() |
274 | .find_map(ast::MacroCall::cast) | 279 | .find_map(ast::MacroCall::cast) |
275 | .unwrap(); | 280 | .unwrap(); |
276 | let tt = macro_call_to_tt(maco_call).unwrap(); | 281 | |
277 | let tt = mbe::parse(&tt); | 282 | let source_file = ast::SourceFile::parse(macro_invocation); |
278 | assert!(tt.is_some()); | 283 | let macro_invocation = source_file |
284 | .syntax() | ||
285 | .descendants() | ||
286 | .find_map(ast::MacroCall::cast) | ||
287 | .unwrap(); | ||
288 | |||
289 | let defenition_tt = macro_call_to_tt(macro_defenition).unwrap(); | ||
290 | let invocation_tt = macro_call_to_tt(macro_invocation).unwrap(); | ||
291 | let mbe = mbe::parse(&defenition_tt).unwrap(); | ||
292 | let expansion = mbe::exapnd(&mbe, &invocation_tt).unwrap(); | ||
293 | assert_eq!( | ||
294 | expansion.to_string(), | ||
295 | "{(impl From < Leaf > for TokenTree {fn from (it : Leaf) - > TokenTree {TokenTree : : Leaf (it)}}) \ | ||
296 | (impl From < Subtree > for TokenTree {fn from (it : Subtree) - > TokenTree {TokenTree : : Subtree (it)}})}" | ||
297 | ) | ||
279 | } | 298 | } |