ra_mbe: added test for malformed token in macro invokation
There was a panic where lexer returned None on malformed tokens. But now we just ignore tokenization errors in mbe.
This commit is contained in:
parent
93a19bda17
commit
28bdb65407
@ -1374,14 +1374,22 @@ pub(crate) struct MacroFixture {
|
||||
|
||||
impl MacroFixture {
|
||||
pub(crate) fn expand_tt(&self, invocation: &str) -> tt::Subtree {
|
||||
let source_file = ast::SourceFile::parse(invocation).ok().unwrap();
|
||||
self.try_expand_tt(invocation).unwrap()
|
||||
}
|
||||
|
||||
fn try_expand_tt(&self, invocation: &str) -> Result<tt::Subtree, ExpandError> {
|
||||
let source_file = ast::SourceFile::parse(invocation).tree();
|
||||
let macro_invocation =
|
||||
source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap();
|
||||
|
||||
let (invocation_tt, _) =
|
||||
ast_to_token_tree(¯o_invocation.token_tree().unwrap()).unwrap();
|
||||
|
||||
self.rules.expand(&invocation_tt).unwrap()
|
||||
self.rules.expand(&invocation_tt)
|
||||
}
|
||||
|
||||
fn assert_expand_err(&self, invocation: &str, err: &ExpandError) {
|
||||
assert_eq!(self.try_expand_tt(invocation).as_ref(), Err(err));
|
||||
}
|
||||
|
||||
fn expand_items(&self, invocation: &str) -> SyntaxNode {
|
||||
@ -1448,7 +1456,7 @@ fn assert_expansion(&self, kind: FragmentKind, invocation: &str, expected: &str)
|
||||
|
||||
pub(crate) fn parse_macro(macro_definition: &str) -> MacroFixture {
|
||||
let source_file = ast::SourceFile::parse(macro_definition).ok().unwrap();
|
||||
let macro_definition =
|
||||
let macro_definition: ast::MacroCall =
|
||||
source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap();
|
||||
|
||||
let (definition_tt, _) = ast_to_token_tree(¯o_definition.token_tree().unwrap()).unwrap();
|
||||
@ -1539,3 +1547,13 @@ macro_rules! foo {
|
||||
)
|
||||
.assert_expand_items("foo!(b0 b1);", "b0 b1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expand_bad_literal() {
|
||||
parse_macro(
|
||||
r#"
|
||||
macro_rules! foo { ($i:literal) => {}; }
|
||||
"#,
|
||||
)
|
||||
.assert_expand_err(r#"foo!(&k");"#, &ExpandError::NoMatchingRule);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user