From 2fd909aa0f84d805ec9e393535850a2f5633ddad Mon Sep 17 00:00:00 2001 From: EdJoPaTo Date: Wed, 15 May 2024 14:45:01 +0200 Subject: [PATCH] refactor(flatten): improve variable/test names --- src/flatten.rs | 54 +++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/flatten.rs b/src/flatten.rs index 4d671e8..8f4a7b9 100644 --- a/src/flatten.rs +++ b/src/flatten.rs @@ -11,7 +11,7 @@ pub struct Flattened<'text, Identifier> { } impl Flattened<'_, Identifier> { - /// Zero based depth. Depth 0 means 0 indentation. + /// Zero based depth. Depth 0 means top level with 0 indentation. #[must_use] pub fn depth(&self) -> usize { self.identifier.len() - 1 @@ -23,7 +23,7 @@ impl Flattened<'_, Identifier> { /// `current` starts empty: `&[]` #[must_use] pub fn flatten<'text, Identifier>( - opened: &HashSet>, + open_identifiers: &HashSet>, items: &'text [TreeItem<'text, Identifier>], current: &[Identifier], ) -> Vec> @@ -35,9 +35,9 @@ where let mut child_identifier = current.to_vec(); child_identifier.push(item.identifier.clone()); - let child_result = opened + let child_result = open_identifiers .contains(&child_identifier) - .then(|| flatten(opened, &item.children, &child_identifier)); + .then(|| flatten(open_identifiers, &item.children, &child_identifier)); result.push(Flattened { identifier: child_identifier, @@ -53,10 +53,10 @@ where #[test] fn depth_works() { - let mut opened = HashSet::new(); - opened.insert(vec!["b"]); - opened.insert(vec!["b", "d"]); - let depths = flatten(&opened, &TreeItem::example(), &[]) + let mut open = HashSet::new(); + open.insert(vec!["b"]); + open.insert(vec!["b", "d"]); + let depths = flatten(&open, &TreeItem::example(), &[]) .into_iter() .map(|flattened| flattened.depth()) .collect::>(); @@ -64,9 +64,9 @@ fn depth_works() { } #[cfg(test)] -fn flatten_works(opened: &HashSet>, expected: &[&str]) { +fn flatten_works(open: &HashSet>, expected: &[&str]) { let items = TreeItem::example(); - let result = flatten(opened, &items, &[]); + let result = flatten(open, &items, &[]); let actual = result .into_iter() .map(|flattened| flattened.identifier.into_iter().last().unwrap()) @@ -75,30 +75,30 @@ fn flatten_works(opened: &HashSet>, expected: &[&str]) { } #[test] -fn get_opened_nothing_opened_is_top_level() { - let opened = HashSet::new(); - flatten_works(&opened, &["a", "b", "h"]); +fn flatten_nothing_open_is_top_level() { + let open = HashSet::new(); + flatten_works(&open, &["a", "b", "h"]); } #[test] -fn get_opened_wrong_opened_is_only_top_level() { - let mut opened = HashSet::new(); - opened.insert(vec!["a"]); - opened.insert(vec!["b", "d"]); - flatten_works(&opened, &["a", "b", "h"]); +fn flatten_wrong_open_is_only_top_level() { + let mut open = HashSet::new(); + open.insert(vec!["a"]); + open.insert(vec!["b", "d"]); + flatten_works(&open, &["a", "b", "h"]); } #[test] -fn get_opened_one_is_opened() { - let mut opened = HashSet::new(); - opened.insert(vec!["b"]); - flatten_works(&opened, &["a", "b", "c", "d", "g", "h"]); +fn flatten_one_is_open() { + let mut open = HashSet::new(); + open.insert(vec!["b"]); + flatten_works(&open, &["a", "b", "c", "d", "g", "h"]); } #[test] -fn get_opened_all_opened() { - let mut opened = HashSet::new(); - opened.insert(vec!["b"]); - opened.insert(vec!["b", "d"]); - flatten_works(&opened, &["a", "b", "c", "d", "e", "f", "g", "h"]); +fn flatten_all_open() { + let mut open = HashSet::new(); + open.insert(vec!["b"]); + open.insert(vec!["b", "d"]); + flatten_works(&open, &["a", "b", "c", "d", "e", "f", "g", "h"]); }