feat: reverse iteration through node parents (#3214)

This commit is contained in:
vanaigr 2024-04-23 09:19:57 -05:00 committed by GitHub
parent 0f125e2d09
commit 90e0e28b95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 84 additions and 24 deletions

View file

@ -168,6 +168,22 @@ fn test_node_child() {
assert_eq!(object_node.parent().unwrap(), array_node);
assert_eq!(array_node.parent().unwrap(), tree.root_node());
assert_eq!(tree.root_node().parent(), None);
assert_eq!(
tree.root_node()
.child_containing_descendant(null_node)
.unwrap(),
array_node
);
assert_eq!(
array_node.child_containing_descendant(null_node).unwrap(),
object_node
);
assert_eq!(
object_node.child_containing_descendant(null_node).unwrap(),
pair_node
);
assert_eq!(pair_node.child_containing_descendant(null_node), None);
}
#[test]
@ -267,6 +283,12 @@ fn test_parent_of_zero_width_node() {
assert_eq!(block.to_string(), "(block)");
assert_eq!(block_parent.kind(), "function_definition");
assert_eq!(block_parent.to_string(), "(function_definition name: (identifier) parameters: (parameters (identifier)) body: (block))");
assert_eq!(
root.child_containing_descendant(block).unwrap(),
function_definition
);
assert_eq!(function_definition.child_containing_descendant(block), None);
}
#[test]
@ -385,6 +407,22 @@ fn test_node_named_child() {
assert_eq!(object_node.parent().unwrap(), array_node);
assert_eq!(array_node.parent().unwrap(), tree.root_node());
assert_eq!(tree.root_node().parent(), None);
assert_eq!(
tree.root_node()
.child_containing_descendant(null_node)
.unwrap(),
array_node
);
assert_eq!(
array_node.child_containing_descendant(null_node).unwrap(),
object_node
);
assert_eq!(
object_node.child_containing_descendant(null_node).unwrap(),
pair_node
);
assert_eq!(pair_node.child_containing_descendant(null_node), None);
}
#[test]