mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Add test for delim bug
This commit is contained in:
parent
92b561b5c7
commit
27c516970b
2 changed files with 149 additions and 14 deletions
|
@ -427,22 +427,28 @@ MACRO_ITEMS@[0; 40)
|
|||
);
|
||||
}
|
||||
|
||||
fn to_subtree(tt: &tt::TokenTree) -> &tt::Subtree {
|
||||
if let tt::TokenTree::Subtree(subtree) = tt {
|
||||
return &subtree;
|
||||
}
|
||||
unreachable!("It is not a subtree");
|
||||
}
|
||||
fn to_literal(tt: &tt::TokenTree) -> &tt::Literal {
|
||||
if let tt::TokenTree::Leaf(tt::Leaf::Literal(lit)) = tt {
|
||||
return lit;
|
||||
}
|
||||
unreachable!("It is not a literal");
|
||||
}
|
||||
|
||||
fn to_punct(tt: &tt::TokenTree) -> &tt::Punct {
|
||||
if let tt::TokenTree::Leaf(tt::Leaf::Punct(lit)) = tt {
|
||||
return lit;
|
||||
}
|
||||
unreachable!("It is not a Punct");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expand_literals_to_token_tree() {
|
||||
fn to_subtree(tt: &tt::TokenTree) -> &tt::Subtree {
|
||||
if let tt::TokenTree::Subtree(subtree) = tt {
|
||||
return &subtree;
|
||||
}
|
||||
unreachable!("It is not a subtree");
|
||||
}
|
||||
|
||||
fn to_literal(tt: &tt::TokenTree) -> &tt::Literal {
|
||||
if let tt::TokenTree::Leaf(tt::Leaf::Literal(lit)) = tt {
|
||||
return lit;
|
||||
}
|
||||
unreachable!("It is not a literal");
|
||||
}
|
||||
|
||||
let expansion = parse_macro(
|
||||
r#"
|
||||
macro_rules! literals {
|
||||
|
@ -470,6 +476,22 @@ fn test_expand_literals_to_token_tree() {
|
|||
assert_eq!(to_literal(&stm_tokens[15 + 3]).text, "\"rust1\"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_attr_to_token_tree() {
|
||||
let expansion = parse_to_token_tree_by_syntax(
|
||||
r#"
|
||||
#[derive(Copy)]
|
||||
struct Foo;
|
||||
"#,
|
||||
);
|
||||
|
||||
assert_eq!(to_punct(&expansion.token_trees[0]).char, '#');
|
||||
assert_eq!(
|
||||
to_subtree(&expansion.token_trees[1]).delimiter_kind(),
|
||||
Some(tt::DelimiterKind::Bracket)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_two_idents() {
|
||||
parse_macro(
|
||||
|
@ -1517,6 +1539,16 @@ pub(crate) fn parse_macro(ra_fixture: &str) -> MacroFixture {
|
|||
MacroFixture { rules }
|
||||
}
|
||||
|
||||
pub(crate) fn parse_to_token_tree_by_syntax(ra_fixture: &str) -> tt::Subtree {
|
||||
let source_file = ast::SourceFile::parse(ra_fixture).ok().unwrap();
|
||||
let tt = syntax_node_to_token_tree(source_file.syntax()).unwrap().0;
|
||||
|
||||
let parsed = parse_to_token_tree(ra_fixture).unwrap().0;
|
||||
assert_eq!(tt, parsed);
|
||||
|
||||
parsed
|
||||
}
|
||||
|
||||
fn debug_dump_ignore_spaces(node: &ra_syntax::SyntaxNode) -> String {
|
||||
let mut level = 0;
|
||||
let mut buf = String::new();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue