mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
First integration test
This test needs neatening but it is the first example of a working integration test
This commit is contained in:
+15
-9
@@ -1,8 +1,7 @@
|
||||
extern crate ansi_term;
|
||||
|
||||
use dust::Node;
|
||||
use std::cmp;
|
||||
use self::ansi_term::Colour::Fixed;
|
||||
use dust::Node;
|
||||
|
||||
static UNITS: [char; 4] = ['T', 'G', 'M', 'K'];
|
||||
|
||||
@@ -77,18 +76,25 @@ fn display_node<S: Into<String>>(
|
||||
}
|
||||
}
|
||||
|
||||
fn print_this_node(node_to_print: &Node, is_biggest: bool, indentation_str: &str) {
|
||||
let padded_size = format!("{:>5}", human_readable_number(node_to_print.size()),);
|
||||
fn print_this_node(node: &Node, is_biggest: bool, indentation: &str) {
|
||||
let pretty_size = format!("{:>5}", human_readable_number(node.size()),);
|
||||
println!(
|
||||
"{}",
|
||||
format_string(node.name(), is_biggest, pretty_size.as_ref(), indentation)
|
||||
)
|
||||
}
|
||||
|
||||
pub fn format_string(dir_name: &str, is_biggest: bool, size: &str, indentation: &str) -> String {
|
||||
format!(
|
||||
"{} {} {}",
|
||||
if is_biggest {
|
||||
Fixed(196).paint(padded_size)
|
||||
Fixed(196).paint(size)
|
||||
} else {
|
||||
Fixed(7).paint(padded_size)
|
||||
Fixed(7).paint(size)
|
||||
},
|
||||
indentation_str,
|
||||
node_to_print.name()
|
||||
);
|
||||
indentation,
|
||||
dir_name,
|
||||
)
|
||||
}
|
||||
|
||||
fn human_readable_number(size: u64) -> (String) {
|
||||
|
||||
+6
-2
@@ -1,13 +1,14 @@
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
extern crate assert_cli;
|
||||
extern crate dust;
|
||||
|
||||
use self::display::draw_it;
|
||||
use clap::{App, AppSettings, Arg};
|
||||
use utils::{find_big_ones, get_dir_tree};
|
||||
use self::display::draw_it;
|
||||
|
||||
mod utils;
|
||||
mod display;
|
||||
mod utils;
|
||||
|
||||
static DEFAULT_NUMBER_OF_LINES: &'static str = "15";
|
||||
|
||||
@@ -42,3 +43,6 @@ fn main() {
|
||||
let slice_it = find_big_ones(&node_per_top_level_dir, number_of_lines);
|
||||
draw_it(permissions, &node_per_top_level_dir, &slice_it);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
hello
|
||||
@@ -0,0 +1,28 @@
|
||||
extern crate ansi_term;
|
||||
use super::*;
|
||||
use display::format_string;
|
||||
|
||||
// TESTS TODO:
|
||||
// handle recursive dirs
|
||||
// handle soft links
|
||||
// handle hard links
|
||||
|
||||
#[test]
|
||||
pub fn test_main() {
|
||||
let r = format!(
|
||||
"{}
|
||||
{}
|
||||
{}
|
||||
{}",
|
||||
format_string("src/test_dir", true, " 4.0K", ""),
|
||||
format_string("src/test_dir/many", true, " 4.0K", "└─┬",),
|
||||
format_string("src/test_dir/many/hello_file", true, " 4.0K", " ├──",),
|
||||
format_string("src/test_dir/many/a_file", false, " 0B", " └──",),
|
||||
);
|
||||
|
||||
assert_cli::Assert::main_binary()
|
||||
.with_args(&["src/test_dir"])
|
||||
.stdout()
|
||||
.is(r)
|
||||
.unwrap();
|
||||
}
|
||||
Reference in New Issue
Block a user