From 59347388541388347e86de9718bd69994c113203 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 31 Jan 2019 17:16:02 +0300 Subject: first test sort-of passes --- crates/ra_hir/src/macros.rs | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir/src') 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 { #[test] fn test_convert_tt() { - let text = r#" + let macro_defenition = r#" macro_rules! impl_froms { ($e:ident: $($v:ident),*) => { $( @@ -267,13 +267,32 @@ macro_rules! impl_froms { } } "#; - let source_file = ast::SourceFile::parse(text); - let maco_call = source_file + + let macro_invocation = r#" +impl_froms!(TokenTree: Leaf, Subtree); +"#; + + let source_file = ast::SourceFile::parse(macro_defenition); + let macro_defenition = source_file .syntax() .descendants() .find_map(ast::MacroCall::cast) .unwrap(); - let tt = macro_call_to_tt(maco_call).unwrap(); - let tt = mbe::parse(&tt); - assert!(tt.is_some()); + + let source_file = ast::SourceFile::parse(macro_invocation); + let macro_invocation = source_file + .syntax() + .descendants() + .find_map(ast::MacroCall::cast) + .unwrap(); + + let defenition_tt = macro_call_to_tt(macro_defenition).unwrap(); + let invocation_tt = macro_call_to_tt(macro_invocation).unwrap(); + let mbe = mbe::parse(&defenition_tt).unwrap(); + let expansion = mbe::exapnd(&mbe, &invocation_tt).unwrap(); + assert_eq!( + expansion.to_string(), + "{(impl From < Leaf > for TokenTree {fn from (it : Leaf) - > TokenTree {TokenTree : : Leaf (it)}}) \ + (impl From < Subtree > for TokenTree {fn from (it : Subtree) - > TokenTree {TokenTree : : Subtree (it)}})}" + ) } -- cgit v1.2.3