Refactor macro tests
This commit is contained in:
parent
e17dcc45a6
commit
6edc54a1e6
3 changed files with 293 additions and 407 deletions
|
@ -476,7 +476,7 @@ impl<'a> TreeSink for TtTreeSink<'a> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::tests::{create_rules, expand};
|
use crate::tests::parse_macro;
|
||||||
use ra_parser::TokenSource;
|
use ra_parser::TokenSource;
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
algo::{insert_children, InsertPosition},
|
algo::{insert_children, InsertPosition},
|
||||||
|
@ -485,7 +485,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn convert_tt_token_source() {
|
fn convert_tt_token_source() {
|
||||||
let rules = create_rules(
|
let expansion = parse_macro(
|
||||||
r#"
|
r#"
|
||||||
macro_rules! literals {
|
macro_rules! literals {
|
||||||
($i:ident) => {
|
($i:ident) => {
|
||||||
|
@ -498,8 +498,8 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
)
|
||||||
let expansion = expand(&rules, "literals!(foo);");
|
.expand_tt("literals!(foo);");
|
||||||
let tts = &[expansion.into()];
|
let tts = &[expansion.into()];
|
||||||
let buffer = tt::buffer::TokenBuffer::new(tts);
|
let buffer = tt::buffer::TokenBuffer::new(tts);
|
||||||
let mut tt_src = SubtreeTokenSource::new(&buffer);
|
let mut tt_src = SubtreeTokenSource::new(&buffer);
|
||||||
|
@ -527,7 +527,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn stmts_token_trees_to_expr_is_err() {
|
fn stmts_token_trees_to_expr_is_err() {
|
||||||
let rules = create_rules(
|
let expansion = parse_macro(
|
||||||
r#"
|
r#"
|
||||||
macro_rules! stmts {
|
macro_rules! stmts {
|
||||||
() => {
|
() => {
|
||||||
|
@ -538,8 +538,8 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
)
|
||||||
let expansion = expand(&rules, "stmts!();");
|
.expand_tt("stmts!();");
|
||||||
assert!(token_tree_to_syntax_node(&expansion, FragmentKind::Expr).is_err());
|
assert!(token_tree_to_syntax_node(&expansion, FragmentKind::Expr).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -83,6 +83,7 @@ pub fn parse(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
|
||||||
parse_from_tokens(token_source, tree_sink, grammar::root);
|
parse_from_tokens(token_source, tree_sink, grammar::root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub enum FragmentKind {
|
pub enum FragmentKind {
|
||||||
Path,
|
Path,
|
||||||
Expr,
|
Expr,
|
||||||
|
|
Loading…
Add table
Reference in a new issue