fix(lib)!: child_containing_descendant now returns direct children

Previously, `child_containing_descendant` would return `null` when
called on a node's direct parent. In my opinion, this doesn't make much
sense; it seems like a node would contain itself. This (breaking)
commit changes the function so that it can return direct children.
This commit is contained in:
Riley Bruins 2024-09-29 11:26:18 -07:00 committed by Amaan Qureshi
parent 6b1ebd3d29
commit b36ef4b7f4
2 changed files with 22 additions and 6 deletions

View file

@ -182,7 +182,11 @@ fn test_node_child() {
object_node.child_containing_descendant(null_node).unwrap(),
pair_node
);
assert_eq!(pair_node.child_containing_descendant(null_node), None);
assert_eq!(
pair_node.child_containing_descendant(null_node).unwrap(),
null_node
);
assert_eq!(null_node.child_containing_descendant(null_node), None);
}
#[test]
@ -287,7 +291,13 @@ fn test_parent_of_zero_width_node() {
root.child_containing_descendant(block).unwrap(),
function_definition
);
assert_eq!(function_definition.child_containing_descendant(block), None);
assert_eq!(
function_definition
.child_containing_descendant(block)
.unwrap(),
block
);
assert_eq!(block.child_containing_descendant(block), None);
let code = "<script></script>";
parser.set_language(&get_language("html")).unwrap();
@ -480,7 +490,11 @@ fn test_node_named_child() {
object_node.child_containing_descendant(null_node).unwrap(),
pair_node
);
assert_eq!(pair_node.child_containing_descendant(null_node), None);
assert_eq!(
pair_node.child_containing_descendant(null_node).unwrap(),
null_node
);
assert_eq!(null_node.child_containing_descendant(null_node), None);
}
#[test]