Add lifetime matcher

This commit is contained in:
Edwin Cheng 2019-04-19 21:15:19 +08:00
parent 59b6cc780b
commit 313854c728
4 changed files with 25 additions and 2 deletions

View file

@ -209,7 +209,6 @@ impl_froms!(TokenTree: Leaf, Subtree);
pub(crate) fn assert_expansion(rules: &MacroRules, invocation: &str, expansion: &str) {
let expanded = expand(rules, invocation);
assert_eq!(expanded.to_string(), expansion);
let tree = token_tree_to_macro_items(&expanded);
@ -786,4 +785,16 @@ MACRO_ITEMS@[0; 40)
);
assert_expansion(&rules, r#"foo! { fn foo() {} }"#, r#"fn foo () {}"#);
}
#[test]
fn test_lifetime() {
let rules = create_rules(
r#"
macro_rules! foo {
($ lt:lifetime) => { struct Ref<$ lt>{ s: &$ lt str } }
}
"#,
);
assert_expansion(&rules, r#"foo!{'a}"#, r#"struct Ref < 'a > {s : & 'a str}"#);
}
}