-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First failing test - even though just a guess :D
- Loading branch information
Sebastian Thiel
committed
Jun 2, 2019
1 parent
396ab0b
commit 68569c6
Showing
6 changed files
with
67 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,55 @@ | ||
mod app { | ||
use dua::interactive::App; | ||
use dua::{ByteFormat, Color, WalkOptions}; | ||
use dua::interactive::{App, ItemData, Tree}; | ||
use dua::{ByteFormat, Color, Sorting, WalkOptions}; | ||
use failure::Error; | ||
use std::path::Path; | ||
use pretty_assertions::assert_eq; | ||
use std::{ffi::OsString, fmt, path::Path}; | ||
use tui::backend::TestBackend; | ||
use tui::Terminal; | ||
|
||
fn debug(item: impl fmt::Debug) -> String { | ||
format!("{:?}", item) | ||
} | ||
|
||
#[test] | ||
fn journey_with_single_path() -> Result<(), Error> { | ||
let mut terminal = Terminal::new(TestBackend::new(40, 20))?; | ||
let input = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/sample-01"); | ||
let (terminal, app) = initialized_app_and_terminal("sample-01")?; | ||
let expected_tree = sample_01_tree(); | ||
|
||
assert_eq!( | ||
debug(app.tree), | ||
debug(expected_tree), | ||
"filesystem graph is stable and matches the directory structure" | ||
); | ||
Ok(()) | ||
} | ||
|
||
fn initialized_app_and_terminal( | ||
fixture_path: &str, | ||
) -> Result<(Terminal<TestBackend>, App), Error> { | ||
let mut terminal = Terminal::new(TestBackend::new(40, 20))?; | ||
let input = Path::new(env!("CARGO_MANIFEST_DIR")) | ||
.join("tests/fixtures") | ||
.join(fixture_path); | ||
let app = App::initialize( | ||
&mut terminal, | ||
WalkOptions { | ||
threads: 1, | ||
byte_format: ByteFormat::Metric, | ||
color: Color::None, | ||
sorting: Sorting::AlphabeticalByFileName, | ||
}, | ||
vec![input], | ||
)?; | ||
Ok(()) | ||
Ok((terminal, app)) | ||
} | ||
|
||
fn sample_01_tree() -> Tree { | ||
let mut expected_tree = Tree::new(); | ||
expected_tree.add_node(ItemData { | ||
name: OsString::from("foo"), | ||
size: 231, | ||
}); | ||
expected_tree | ||
} | ||
} |