aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_mbe/src/tests.rs')
-rw-r--r--crates/ra_mbe/src/tests.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs
index e0d689704..cb228702f 100644
--- a/crates/ra_mbe/src/tests.rs
+++ b/crates/ra_mbe/src/tests.rs
@@ -1374,14 +1374,22 @@ pub(crate) struct MacroFixture {
1374 1374
1375impl MacroFixture { 1375impl MacroFixture {
1376 pub(crate) fn expand_tt(&self, invocation: &str) -> tt::Subtree { 1376 pub(crate) fn expand_tt(&self, invocation: &str) -> tt::Subtree {
1377 let source_file = ast::SourceFile::parse(invocation).ok().unwrap(); 1377 self.try_expand_tt(invocation).unwrap()
1378 }
1379
1380 fn try_expand_tt(&self, invocation: &str) -> Result<tt::Subtree, ExpandError> {
1381 let source_file = ast::SourceFile::parse(invocation).tree();
1378 let macro_invocation = 1382 let macro_invocation =
1379 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); 1383 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap();
1380 1384
1381 let (invocation_tt, _) = 1385 let (invocation_tt, _) =
1382 ast_to_token_tree(&macro_invocation.token_tree().unwrap()).unwrap(); 1386 ast_to_token_tree(&macro_invocation.token_tree().unwrap()).unwrap();
1383 1387
1384 self.rules.expand(&invocation_tt).unwrap() 1388 self.rules.expand(&invocation_tt)
1389 }
1390
1391 fn assert_expand_err(&self, invocation: &str, err: &ExpandError) {
1392 assert_eq!(self.try_expand_tt(invocation).as_ref(), Err(err));
1385 } 1393 }
1386 1394
1387 fn expand_items(&self, invocation: &str) -> SyntaxNode { 1395 fn expand_items(&self, invocation: &str) -> SyntaxNode {
@@ -1539,3 +1547,13 @@ fn test_repeat_bad_var() {
1539 ) 1547 )
1540 .assert_expand_items("foo!(b0 b1);", "b0 b1"); 1548 .assert_expand_items("foo!(b0 b1);", "b0 b1");
1541} 1549}
1550
1551#[test]
1552fn test_expand_bad_literal() {
1553 parse_macro(
1554 r#"
1555 macro_rules! foo { ($i:literal) => {}; }
1556 "#,
1557 )
1558 .assert_expand_err(r#"foo!(&k");"#, &ExpandError::NoMatchingRule);
1559}