test(flatten): ensure depth works
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user