move fuzz-invariants to the library

This commit is contained in:
Aleksey Kladov 2018-09-08 18:34:41 +03:00
parent a60b9ad963
commit ba4a697d8c
3 changed files with 44 additions and 41 deletions

View file

@ -66,7 +66,9 @@ impl File {
fn new(green: GreenNode, errors: Vec<SyntaxError>) -> File {
let root = SyntaxRoot::new(green, errors);
let root = SyntaxNode::new_owned(root);
validate_block_structure(root.borrowed());
if cfg!(debug_assertions) {
utils::validate_block_structure(root.borrowed());
}
File { root }
}
pub fn parse(text: &str) -> File {
@ -112,40 +114,6 @@ impl File {
}
}
#[cfg(not(debug_assertions))]
fn validate_block_structure(_: SyntaxNodeRef) {}
#[cfg(debug_assertions)]
fn validate_block_structure(root: SyntaxNodeRef) {
let mut stack = Vec::new();
for node in algo::walk::preorder(root) {
match node.kind() {
SyntaxKind::L_CURLY => {
stack.push(node)
}
SyntaxKind::R_CURLY => {
if let Some(pair) = stack.pop() {
assert_eq!(
node.parent(),
pair.parent(),
"\nunpaired curleys:\n{}\n{}\n",
root.text(),
utils::dump_tree(root),
);
assert!(
node.next_sibling().is_none() && pair.prev_sibling().is_none(),
"\nfloating curlys at {:?}\nfile:\n{}\nerror:\n{}\n",
node,
root.text(),
node.text(),
);
}
}
_ => (),
}
}
}
#[derive(Debug, Clone)]
pub struct AtomEdit {
pub delete: TextRange,