diff --git a/src/display.rs b/src/display.rs index 510c251..da78bbf 100644 --- a/src/display.rs +++ b/src/display.rs @@ -53,7 +53,7 @@ impl DisplayData { } } - fn biggest(&self, num_siblings: u64, max_siblings: u64) -> bool { + fn is_biggest(&self, num_siblings: u64, max_siblings: u64) -> bool { if self.is_reversed { num_siblings == 0 } else { @@ -102,7 +102,7 @@ fn display_node(node: Node, is_biggest: bool, indent: &str, display_data: &Displ for c in display_data.get_children_from_node(node) { num_siblings -= 1; let chars = display_data.get_tree_chars(num_siblings, max_sibling, c.children.len() > 0); - let is_biggest = display_data.biggest(num_siblings, max_sibling); + let is_biggest = display_data.is_biggest(num_siblings, max_sibling); let full_indent = new_indent.clone() + chars; display_node(*c, is_biggest, &*full_indent, display_data) } @@ -133,16 +133,10 @@ fn print_this_node(name: &str, size: u64, is_biggest: bool, short_paths: bool, i let pretty_size = format!("{:>5}", human_readable_number(size),); println!( "{}", - format_string( - name, - is_biggest, - short_paths, - pretty_size.as_ref(), - indentation - ) + format_string(name, is_biggest, short_paths, &*pretty_size, indentation) ) } -// idea: squash these 2 + pub fn format_string( dir_name: &str, is_biggest: bool, diff --git a/src/tests.rs b/src/tests.rs index 0e72534..096c128 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -109,6 +109,27 @@ pub fn test_apparent_size() { .unwrap(); } +#[test] +pub fn test_reverse_flag() { + // variable names the same length make the output easier to read + let a = " ┌── a_file"; + let b = " ├── hello_file"; + let c = " ┌─┴ many"; + let d = " ─┴ test_dir"; + + assert_cli::Assert::main_binary() + .with_args(&["-r", "src/test_dir"]) + .stdout() + .contains(a) + .stdout() + .contains(b) + .stdout() + .contains(c) + .stdout() + .contains(d) + .unwrap(); +} + #[test] pub fn test_d_flag_works() { // We should see the top level directory but not the sub dirs / files: