mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 09:27:27 +00:00
Reorganize mbe tests
This commit is contained in:
parent
f7fbea509f
commit
49b876de09
3 changed files with 1952 additions and 1959 deletions
File diff suppressed because it is too large
Load diff
1872
crates/mbe/src/tests/expand.rs
Normal file
1872
crates/mbe/src/tests/expand.rs
Normal file
File diff suppressed because it is too large
Load diff
45
crates/mbe/src/tests/rule.rs
Normal file
45
crates/mbe/src/tests/rule.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
use syntax::{ast, AstNode};
|
||||
|
||||
use crate::ast_to_token_tree;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_valid_arms() {
|
||||
fn check(macro_body: &str) {
|
||||
let m = parse_macro_arm(macro_body);
|
||||
m.unwrap();
|
||||
}
|
||||
|
||||
check("($i:ident) => ()");
|
||||
check("($($i:ident)*) => ($_)");
|
||||
check("($($true:ident)*) => ($true)");
|
||||
check("($($false:ident)*) => ($false)");
|
||||
check("($) => ($)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_arms() {
|
||||
fn check(macro_body: &str, err: ParseError) {
|
||||
let m = parse_macro_arm(macro_body);
|
||||
assert_eq!(m, Err(err));
|
||||
}
|
||||
check("invalid", ParseError::Expected("expected subtree".into()));
|
||||
|
||||
check("$i:ident => ()", ParseError::Expected("expected subtree".into()));
|
||||
check("($i:ident) ()", ParseError::Expected("expected `=`".into()));
|
||||
check("($($i:ident)_) => ()", ParseError::InvalidRepeat);
|
||||
|
||||
check("($i) => ($i)", ParseError::UnexpectedToken("bad fragment specifier 1".into()));
|
||||
check("($i:) => ($i)", ParseError::UnexpectedToken("bad fragment specifier 1".into()));
|
||||
}
|
||||
|
||||
fn parse_macro_arm(arm_definition: &str) -> Result<crate::MacroRules, ParseError> {
|
||||
let macro_definition = format!(" macro_rules! m {{ {} }} ", arm_definition);
|
||||
let source_file = ast::SourceFile::parse(¯o_definition).ok().unwrap();
|
||||
let macro_definition =
|
||||
source_file.syntax().descendants().find_map(ast::MacroRules::cast).unwrap();
|
||||
|
||||
let (definition_tt, _) = ast_to_token_tree(¯o_definition.token_tree().unwrap()).unwrap();
|
||||
crate::MacroRules::parse(&definition_tt)
|
||||
}
|
Loading…
Reference in a new issue