Make sure we match the entire pattern

This commit is contained in:
Jeff Muizelaar 2019-02-03 10:06:09 -05:00
parent f370393bba
commit dbc3074556
2 changed files with 34 additions and 1 deletions

View file

@ -176,7 +176,7 @@ impl_froms!(TokenTree: Leaf, Subtree);
}
#[test]
fn test_fail_match_pattern_by_token() {
fn test_fail_match_pattern_by_first_token() {
let macro_definition = r#"
macro_rules! foo {
($ i:ident) => (
@ -206,4 +206,34 @@ impl_froms!(TokenTree: Leaf, Subtree);
assert_expansion(&rules, "foo! { + Baz }", "struct Baz ;");
}
#[test]
fn test_fail_match_pattern_by_last_token() {
let macro_definition = r#"
macro_rules! foo {
($ i:ident) => (
mod $ i {}
);
($ i:ident =) => (
fn $ i() {}
);
($ i:ident +) => (
struct $ i;
)
}
"#;
let source_file = ast::SourceFile::parse(macro_definition);
let macro_definition = source_file
.syntax()
.descendants()
.find_map(ast::MacroCall::cast)
.unwrap();
let definition_tt = ast_to_token_tree(macro_definition.token_tree().unwrap()).unwrap();
let rules = crate::MacroRules::parse(&definition_tt).unwrap();
assert_expansion(&rules, "foo! { foo }", "mod foo {}");
assert_expansion(&rules, "foo! { bar = }", "fn bar () {}");
assert_expansion(&rules, "foo! { Baz + }", "struct Baz ;");
}
}