From 68569c69f5fdeedddd45635e8eb6d0c255de53f4 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 2 Jun 2019 14:08:49 +0530 Subject: First failing test - even though just a guess :D --- tests/interactive.rs | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/interactive.rs b/tests/interactive.rs index 52ae8bc..1ea19d4 100644 --- a/tests/interactive.rs +++ b/tests/interactive.rs @@ -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, 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 } } -- cgit v1.2.3