pub fn validate_tree(node: &SyntaxNode<Lang>) -> Result<(), String>Expand description
Validates that the CST follows expected structural invariants.
This is useful for testing that mutations don’t break tree structure.
Returns Ok(()) if the tree is valid, or an error message if issues are found.
Current checks:
- Every MAPPING_ENTRY has exactly one KEY
- Every MAPPING_ENTRY has exactly one COLON
- Every MAPPING_ENTRY has at most one VALUE
- Block-style MAPPING_ENTRY and SEQUENCE_ENTRY nodes end with NEWLINE
§Example
use yaml_edit::{YamlFile, debug};
use rowan::ast::AstNode;
use std::str::FromStr;
let yaml = YamlFile::from_str("name: Alice\n").unwrap();
debug::validate_tree(yaml.syntax()).expect("Tree should be valid");