diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2020-03-15 20:03:03 +0800 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2020-03-15 20:03:03 +0800 |
commit | b26f8ff07730c6d0ba21cd2db398539a1252bf7a (patch) | |
tree | ca408dafd97f5dfad8f0c4350a587e2c651a7ee6 | |
parent | d53fd5067daecd6e2e7affec917f594fd4e951c6 (diff) |
adapt journey tests to changed signature
related to #42
-rw-r--r-- | src/interactive/app/eventloop.rs | 9 | ||||
-rw-r--r-- | src/interactive/app_test/journeys_readonly.rs | 47 | ||||
-rw-r--r-- | src/interactive/app_test/journeys_with_writes.rs | 8 | ||||
-rw-r--r-- | src/interactive/app_test/utils.rs | 6 |
4 files changed, 35 insertions, 35 deletions
diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs index c166697..88f2c11 100644 --- a/src/interactive/app/eventloop.rs +++ b/src/interactive/app/eventloop.rs @@ -8,12 +8,7 @@ use dua::{ WalkOptions, WalkResult, }; use failure::Error; -use std::{ - collections::BTreeMap, - io, - path::PathBuf, - io::Write -}; +use std::{collections::BTreeMap, io, io::Write, path::PathBuf}; use termion::event::Key; use tui::backend::Backend; use tui_react::Terminal; @@ -102,7 +97,7 @@ impl TerminalApp { // Exit 'quickly' to avoid having to wait for all memory to be freed by us. // Let the OS do it - we have nothing to lose, literally. std::process::exit(0); - }, + } Mark => self.state.focussed = Main, Help => { self.state.focussed = Main; diff --git a/src/interactive/app_test/journeys_readonly.rs b/src/interactive/app_test/journeys_readonly.rs index ae4bd0f..8f5eb1a 100644 --- a/src/interactive/app_test/journeys_readonly.rs +++ b/src/interactive/app_test/journeys_readonly.rs @@ -1,9 +1,11 @@ -use crate::interactive::app_test::utils::{ - fixture_str, index_by_name, initialized_app_and_terminal_from_fixture, node_by_index, - node_by_name, +use crate::{ + interactive::app_test::utils::{ + fixture_str, index_by_name, initialized_app_and_terminal_from_fixture, new_test_terminal, + node_by_index, node_by_name, + }, + interactive::app_test::FIXTURE_PATH, + interactive::SortMode, }; -use crate::interactive::app_test::FIXTURE_PATH; -use crate::interactive::SortMode; use failure::Error; use pretty_assertions::assert_eq; use std::ffi::OsString; @@ -13,8 +15,7 @@ use termion::input::TermRead; fn simple_user_journey_read_only() -> Result<(), Error> { let long_root = "sample-02/dir"; let short_root = "sample-01"; - let (mut terminal, mut app) = - initialized_app_and_terminal_from_fixture(&[short_root, long_root])?; + let (terminal, mut app) = initialized_app_and_terminal_from_fixture(&[short_root, long_root])?; // POST-INIT // after initialization, we expect that... @@ -47,7 +48,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> { // SORTING { // when hitting the S key - app.process_events(&mut terminal, b"s".keys())?; + app.process_events(terminal, b"s".keys())?; assert_eq!( app.state.sorting, SortMode::SizeAscending, @@ -59,7 +60,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> { "it recomputes the cached entries" ); // when hitting the S key again - app.process_events(&mut terminal, b"s".keys())?; + app.process_events(new_test_terminal()?, b"s".keys())?; assert_eq!( app.state.sorting, SortMode::SizeDescending, @@ -75,35 +76,35 @@ fn simple_user_journey_read_only() -> Result<(), Error> { // Entry-Navigation { // when hitting the j key - app.process_events(&mut terminal, b"j".keys())?; + app.process_events(new_test_terminal()?, b"j".keys())?; assert_eq!( node_by_name(&app, fixture_str(long_root)), node_by_index(&app, *app.state.selected.as_ref().unwrap()), "it moves the cursor down and selects the next entry based on the current sort mode" ); // when hitting it while there is nowhere to go - app.process_events(&mut terminal, b"j".keys())?; + app.process_events(new_test_terminal()?, b"j".keys())?; assert_eq!( node_by_name(&app, fixture_str(long_root)), node_by_index(&app, *app.state.selected.as_ref().unwrap()), "it stays at the previous position" ); // when hitting the k key - app.process_events(&mut terminal, b"k".keys())?; + app.process_events(new_test_terminal()?, b"k".keys())?; assert_eq!( node_by_name(&app, fixture_str(short_root)), node_by_index(&app, *app.state.selected.as_ref().unwrap()), "it moves the cursor up and selects the next entry based on the current sort mode" ); // when hitting the k key again - app.process_events(&mut terminal, b"k".keys())?; + app.process_events(new_test_terminal()?, b"k".keys())?; assert_eq!( node_by_name(&app, fixture_str(short_root)), node_by_index(&app, *app.state.selected.as_ref().unwrap()), "it stays at the current cursor position as there is nowhere to go" ); // when hitting the o key with a directory selected - app.process_events(&mut terminal, b"o".keys())?; + app.process_events(new_test_terminal()?, b"o".keys())?; { let new_root_idx = index_by_name(&app, fixture_str(short_root)); assert_eq!( @@ -117,7 +118,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> { ); // when hitting the u key while inside a sub-directory - app.process_events(&mut terminal, b"u".keys())?; + app.process_events(new_test_terminal()?, b"u".keys())?; { assert_eq!( app.traversal.root_index, app.state.root, @@ -132,7 +133,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> { } // when hitting the u key while inside of the root directory // We are moving the cursor down just to have a non-default selection - app.process_events(&mut terminal, b"ju".keys())?; + app.process_events(new_test_terminal()?, b"ju".keys())?; { assert_eq!( app.traversal.root_index, app.state.root, @@ -149,9 +150,9 @@ fn simple_user_journey_read_only() -> Result<(), Error> { // Deletion { // when hitting the 'd' key (also move cursor back to start) - app.process_events(&mut terminal, b"k".keys())?; + app.process_events(new_test_terminal()?, b"k".keys())?; let previously_selected_index = *app.state.selected.as_ref().unwrap(); - app.process_events(&mut terminal, b"d".keys())?; + app.process_events(new_test_terminal()?, b"d".keys())?; { assert_eq!( Some(1), @@ -173,7 +174,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> { // when hitting the 'd' key again { - app.process_events(&mut terminal, b"d".keys())?; + app.process_events(new_test_terminal()?, b"d".keys())?; assert_eq!( Some(2), @@ -190,7 +191,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> { // when hitting the 'd' key once again { - app.process_events(&mut terminal, b"d".keys())?; + app.process_events(new_test_terminal()?, b"d".keys())?; assert_eq!( Some(1), @@ -207,7 +208,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> { } // when hitting the spacebar (after moving up to the first entry) { - app.process_events(&mut terminal, b"k ".keys())?; + app.process_events(new_test_terminal()?, b"k ".keys())?; assert_eq!( None, @@ -226,7 +227,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> { // Marking { // select something - app.process_events(&mut terminal, b" j ".keys())?; + app.process_events(new_test_terminal()?, b" j ".keys())?; assert_eq!( Some(false), app.window.mark_pane.as_ref().map(|p| p.has_focus()), @@ -240,7 +241,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> { ); // when advancing the selection to the marker pane - app.process_events(&mut terminal, b"\t".keys())?; + app.process_events(new_test_terminal()?, b"\t".keys())?; { assert_eq!( Some(true), diff --git a/src/interactive/app_test/journeys_with_writes.rs b/src/interactive/app_test/journeys_with_writes.rs index cbd51cd..465be54 100644 --- a/src/interactive/app_test/journeys_with_writes.rs +++ b/src/interactive/app_test/journeys_with_writes.rs @@ -1,5 +1,5 @@ use crate::interactive::app_test::utils::{ - initialized_app_and_terminal_from_paths, WritableFixture, + initialized_app_and_terminal_from_paths, new_test_terminal, WritableFixture, }; use failure::Error; use pretty_assertions::assert_eq; @@ -9,10 +9,10 @@ use termion::input::TermRead; #[test] fn basic_user_journey_with_deletion() -> Result<(), Error> { let fixture = WritableFixture::from("sample-02"); - let (mut terminal, mut app) = initialized_app_and_terminal_from_paths(&[fixture.root.clone()])?; + let (terminal, mut app) = initialized_app_and_terminal_from_paths(&[fixture.root.clone()])?; // With a selection of items - app.process_events(&mut terminal, b"doddd".keys())?; + app.process_events(terminal, b"doddd".keys())?; assert_eq!( app.window.mark_pane.as_ref().map(|p| p.marked().len()), @@ -28,7 +28,7 @@ fn basic_user_journey_with_deletion() -> Result<(), Error> { // When selecting the marker window and pressing the combination to delete entries app.process_events( - &mut terminal, + new_test_terminal()?, vec![Ok(Key::Char('\t')), Ok(Key::Ctrl('r'))].into_iter(), )?; assert_eq!( diff --git a/src/interactive/app_test/utils.rs b/src/interactive/app_test/utils.rs index f59fc2d..f95efce 100644 --- a/src/interactive/app_test/utils.rs +++ b/src/interactive/app_test/utils.rs @@ -155,7 +155,7 @@ pub fn initialized_app_and_terminal_with_closure<P: AsRef<Path>>( fixture_paths: &[P], mut convert: impl FnMut(&Path) -> PathBuf, ) -> Result<(Terminal<TestBackend>, TerminalApp), Error> { - let mut terminal = Terminal::new(TestBackend::new(40, 20))?; + let mut terminal = new_test_terminal()?; std::env::set_current_dir(Path::new(env!("CARGO_MANIFEST_DIR")))?; let input = fixture_paths.iter().map(|c| convert(c.as_ref())).collect(); @@ -174,6 +174,10 @@ pub fn initialized_app_and_terminal_with_closure<P: AsRef<Path>>( Ok((terminal, app)) } +pub fn new_test_terminal() -> std::io::Result<Terminal<TestBackend>> { + Terminal::new(TestBackend::new(40, 20)) +} + pub fn initialized_app_and_terminal_from_paths( fixture_paths: &[PathBuf], ) -> Result<(Terminal<TestBackend>, TerminalApp), Error> { |