diff options
Diffstat (limited to 'tests/src')
| -rw-r--r-- | tests/src/tests.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/tests/src/tests.rs b/tests/src/tests.rs index a867f065..52cc54db 100644 --- a/tests/src/tests.rs +++ b/tests/src/tests.rs @@ -606,7 +606,7 @@ fn test_reparse(text: &str, i: usize, rng: &mut LinearShift) -> bool { } let source = Source::detached(text); - let leafs = source.root().leafs(); + let leafs = leafs(source.root()); let start = source.range(leafs[pick(0..leafs.len())].span()).start; let supplement = supplements[pick(0..supplements.len())]; ok &= apply(start..start, supplement); @@ -614,6 +614,15 @@ fn test_reparse(text: &str, i: usize, rng: &mut LinearShift) -> bool { ok } +/// Returns all leaf descendants of a node (may include itself). +fn leafs(node: &SyntaxNode) -> Vec<SyntaxNode> { + if node.children().len() == 0 { + vec![node.clone()] + } else { + node.children().flat_map(leafs).collect() + } +} + /// Ensure that all spans are properly ordered (and therefore unique). #[track_caller] fn test_spans(root: &SyntaxNode) -> bool { |
