mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
Add test for reverse flag
This commit is contained in:
+4
-10
@@ -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 {
|
if self.is_reversed {
|
||||||
num_siblings == 0
|
num_siblings == 0
|
||||||
} else {
|
} 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) {
|
for c in display_data.get_children_from_node(node) {
|
||||||
num_siblings -= 1;
|
num_siblings -= 1;
|
||||||
let chars = display_data.get_tree_chars(num_siblings, max_sibling, c.children.len() > 0);
|
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;
|
let full_indent = new_indent.clone() + chars;
|
||||||
display_node(*c, is_biggest, &*full_indent, display_data)
|
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),);
|
let pretty_size = format!("{:>5}", human_readable_number(size),);
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
format_string(
|
format_string(name, is_biggest, short_paths, &*pretty_size, indentation)
|
||||||
name,
|
|
||||||
is_biggest,
|
|
||||||
short_paths,
|
|
||||||
pretty_size.as_ref(),
|
|
||||||
indentation
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// idea: squash these 2
|
|
||||||
pub fn format_string(
|
pub fn format_string(
|
||||||
dir_name: &str,
|
dir_name: &str,
|
||||||
is_biggest: bool,
|
is_biggest: bool,
|
||||||
|
|||||||
@@ -109,6 +109,27 @@ pub fn test_apparent_size() {
|
|||||||
.unwrap();
|
.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]
|
#[test]
|
||||||
pub fn test_d_flag_works() {
|
pub fn test_d_flag_works() {
|
||||||
// We should see the top level directory but not the sub dirs / files:
|
// We should see the top level directory but not the sub dirs / files:
|
||||||
|
|||||||
Reference in New Issue
Block a user