Merge #3009
3009: Make sure that newly created nodes are the root of the tree r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
1f7a54cfa7
1 changed files with 11 additions and 2 deletions
|
@ -2,7 +2,7 @@
|
|||
//! of smaller pieces.
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxToken};
|
||||
use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxToken};
|
||||
|
||||
pub fn name(text: &str) -> ast::Name {
|
||||
ast_from_text(&format!("mod {};", text))
|
||||
|
@ -179,7 +179,16 @@ pub fn token(kind: SyntaxKind) -> SyntaxToken {
|
|||
|
||||
fn ast_from_text<N: AstNode>(text: &str) -> N {
|
||||
let parse = SourceFile::parse(text);
|
||||
parse.tree().syntax().descendants().find_map(N::cast).unwrap()
|
||||
let node = parse.tree().syntax().descendants().find_map(N::cast).unwrap();
|
||||
let node = node.syntax().clone();
|
||||
let node = unroot(node);
|
||||
let node = N::cast(node).unwrap();
|
||||
assert_eq!(node.syntax().text_range().start(), 0.into());
|
||||
node
|
||||
}
|
||||
|
||||
fn unroot(n: SyntaxNode) -> SyntaxNode {
|
||||
SyntaxNode::new_root(n.green().clone())
|
||||
}
|
||||
|
||||
pub mod tokens {
|
||||
|
|
Loading…
Add table
Reference in a new issue