Skip to content

Commit

Permalink
tree: add is_leaf field
Browse files Browse the repository at this point in the history
  • Loading branch information
ynqa committed Feb 11, 2024
1 parent 5d91287 commit e50e1ef
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/tree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct NodeWithDepth {
pub data: String,
pub depth: usize,
pub children_visible: bool,
pub is_leaf: bool,
}

impl Node {
Expand Down Expand Up @@ -38,6 +39,7 @@ impl Node {
data: self.data.clone(),
depth,
children_visible: self.children_visible,
is_leaf: self.children.is_empty(),
});

if self.children_visible && !self.children.is_empty() {
Expand Down Expand Up @@ -89,6 +91,7 @@ mod test {
data: String::from("/"),
depth: 0,
children_visible: false,
is_leaf: false,
}],
create_test_node().flatten()
);
Expand Down Expand Up @@ -121,21 +124,25 @@ mod test {
data: String::from("/"),
depth: 0,
children_visible: true,
is_leaf: false,
},
NodeWithDepth {
data: String::from("a"),
depth: 1,
children_visible: false,
is_leaf: false,
},
NodeWithDepth {
data: String::from("b"),
depth: 1,
children_visible: false,
is_leaf: true,
},
NodeWithDepth {
data: String::from("c"),
depth: 1,
children_visible: false,
is_leaf: true,
},
];
assert_eq!(expect, root.flatten());
Expand Down

0 comments on commit e50e1ef

Please sign in to comment.