test(flatten): ensure depth works

This commit is contained in:
EdJoPaTo
2024-05-01 18:06:14 +02:00
parent 537dc8021e
commit e9656f82d1
+13
View File
@@ -11,6 +11,7 @@ pub struct Flattened<'a, Identifier> {
}
impl<'a, Identifier> Flattened<'a, Identifier> {
/// Zero based depth. Depth 0 means 0 indentation.
#[must_use]
pub fn depth(&self) -> usize {
self.identifier.len() - 1
@@ -50,6 +51,18 @@ where
result
}
#[test]
fn depth_works() {
let mut opened = HashSet::new();
opened.insert(vec!["b"]);
opened.insert(vec!["b", "d"]);
let depths = flatten(&opened, &TreeItem::example(), &[])
.into_iter()
.map(|flattened| flattened.depth())
.collect::<Vec<_>>();
assert_eq!(depths, [0, 0, 1, 1, 2, 2, 1, 0]);
}
#[cfg(test)]
fn flatten_works(opened: &HashSet<Vec<&'static str>>, expected: &[&str]) {
let items = TreeItem::example();