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> {
|
impl<'a, Identifier> Flattened<'a, Identifier> {
|
||||||
|
/// Zero based depth. Depth 0 means 0 indentation.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn depth(&self) -> usize {
|
pub fn depth(&self) -> usize {
|
||||||
self.identifier.len() - 1
|
self.identifier.len() - 1
|
||||||
@@ -50,6 +51,18 @@ where
|
|||||||
result
|
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)]
|
#[cfg(test)]
|
||||||
fn flatten_works(opened: &HashSet<Vec<&'static str>>, expected: &[&str]) {
|
fn flatten_works(opened: &HashSet<Vec<&'static str>>, expected: &[&str]) {
|
||||||
let items = TreeItem::example();
|
let items = TreeItem::example();
|
||||||
|
|||||||
Reference in New Issue
Block a user