Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b26f8ff

Browse files
committed
adapt journey tests to changed signature
related to #42
1 parent d53fd50 commit b26f8ff

4 files changed

Lines changed: 35 additions & 35 deletions

File tree

src/interactive/app/eventloop.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ use dua::{
88
WalkOptions, WalkResult,
99
};
1010
use failure::Error;
11-
use std::{
12-
collections::BTreeMap,
13-
io,
14-
path::PathBuf,
15-
io::Write
16-
};
11+
use std::{collections::BTreeMap, io, io::Write, path::PathBuf};
1712
use termion::event::Key;
1813
use tui::backend::Backend;
1914
use tui_react::Terminal;
@@ -102,7 +97,7 @@ impl TerminalApp {
10297
// Exit 'quickly' to avoid having to wait for all memory to be freed by us.
10398
// Let the OS do it - we have nothing to lose, literally.
10499
std::process::exit(0);
105-
},
100+
}
106101
Mark => self.state.focussed = Main,
107102
Help => {
108103
self.state.focussed = Main;

src/interactive/app_test/journeys_readonly.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
use crate::interactive::app_test::utils::{
2-
fixture_str, index_by_name, initialized_app_and_terminal_from_fixture, node_by_index,
3-
node_by_name,
1+
use crate::{
2+
interactive::app_test::utils::{
3+
fixture_str, index_by_name, initialized_app_and_terminal_from_fixture, new_test_terminal,
4+
node_by_index, node_by_name,
5+
},
6+
interactive::app_test::FIXTURE_PATH,
7+
interactive::SortMode,
48
};
5-
use crate::interactive::app_test::FIXTURE_PATH;
6-
use crate::interactive::SortMode;
79
use failure::Error;
810
use pretty_assertions::assert_eq;
911
use std::ffi::OsString;
@@ -13,8 +15,7 @@ use termion::input::TermRead;
1315
fn simple_user_journey_read_only() -> Result<(), Error> {
1416
let long_root = "sample-02/dir";
1517
let short_root = "sample-01";
16-
let (mut terminal, mut app) =
17-
initialized_app_and_terminal_from_fixture(&[short_root, long_root])?;
18+
let (terminal, mut app) = initialized_app_and_terminal_from_fixture(&[short_root, long_root])?;
1819

1920
// POST-INIT
2021
// after initialization, we expect that...
@@ -47,7 +48,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> {
4748
// SORTING
4849
{
4950
// when hitting the S key
50-
app.process_events(&mut terminal, b"s".keys())?;
51+
app.process_events(terminal, b"s".keys())?;
5152
assert_eq!(
5253
app.state.sorting,
5354
SortMode::SizeAscending,
@@ -59,7 +60,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> {
5960
"it recomputes the cached entries"
6061
);
6162
// when hitting the S key again
62-
app.process_events(&mut terminal, b"s".keys())?;
63+
app.process_events(new_test_terminal()?, b"s".keys())?;
6364
assert_eq!(
6465
app.state.sorting,
6566
SortMode::SizeDescending,
@@ -75,35 +76,35 @@ fn simple_user_journey_read_only() -> Result<(), Error> {
7576
// Entry-Navigation
7677
{
7778
// when hitting the j key
78-
app.process_events(&mut terminal, b"j".keys())?;
79+
app.process_events(new_test_terminal()?, b"j".keys())?;
7980
assert_eq!(
8081
node_by_name(&app, fixture_str(long_root)),
8182
node_by_index(&app, *app.state.selected.as_ref().unwrap()),
8283
"it moves the cursor down and selects the next entry based on the current sort mode"
8384
);
8485
// when hitting it while there is nowhere to go
85-
app.process_events(&mut terminal, b"j".keys())?;
86+
app.process_events(new_test_terminal()?, b"j".keys())?;
8687
assert_eq!(
8788
node_by_name(&app, fixture_str(long_root)),
8889
node_by_index(&app, *app.state.selected.as_ref().unwrap()),
8990
"it stays at the previous position"
9091
);
9192
// when hitting the k key
92-
app.process_events(&mut terminal, b"k".keys())?;
93+
app.process_events(new_test_terminal()?, b"k".keys())?;
9394
assert_eq!(
9495
node_by_name(&app, fixture_str(short_root)),
9596
node_by_index(&app, *app.state.selected.as_ref().unwrap()),
9697
"it moves the cursor up and selects the next entry based on the current sort mode"
9798
);
9899
// when hitting the k key again
99-
app.process_events(&mut terminal, b"k".keys())?;
100+
app.process_events(new_test_terminal()?, b"k".keys())?;
100101
assert_eq!(
101102
node_by_name(&app, fixture_str(short_root)),
102103
node_by_index(&app, *app.state.selected.as_ref().unwrap()),
103104
"it stays at the current cursor position as there is nowhere to go"
104105
);
105106
// when hitting the o key with a directory selected
106-
app.process_events(&mut terminal, b"o".keys())?;
107+
app.process_events(new_test_terminal()?, b"o".keys())?;
107108
{
108109
let new_root_idx = index_by_name(&app, fixture_str(short_root));
109110
assert_eq!(
@@ -117,7 +118,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> {
117118
);
118119

119120
// when hitting the u key while inside a sub-directory
120-
app.process_events(&mut terminal, b"u".keys())?;
121+
app.process_events(new_test_terminal()?, b"u".keys())?;
121122
{
122123
assert_eq!(
123124
app.traversal.root_index, app.state.root,
@@ -132,7 +133,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> {
132133
}
133134
// when hitting the u key while inside of the root directory
134135
// We are moving the cursor down just to have a non-default selection
135-
app.process_events(&mut terminal, b"ju".keys())?;
136+
app.process_events(new_test_terminal()?, b"ju".keys())?;
136137
{
137138
assert_eq!(
138139
app.traversal.root_index, app.state.root,
@@ -149,9 +150,9 @@ fn simple_user_journey_read_only() -> Result<(), Error> {
149150
// Deletion
150151
{
151152
// when hitting the 'd' key (also move cursor back to start)
152-
app.process_events(&mut terminal, b"k".keys())?;
153+
app.process_events(new_test_terminal()?, b"k".keys())?;
153154
let previously_selected_index = *app.state.selected.as_ref().unwrap();
154-
app.process_events(&mut terminal, b"d".keys())?;
155+
app.process_events(new_test_terminal()?, b"d".keys())?;
155156
{
156157
assert_eq!(
157158
Some(1),
@@ -173,7 +174,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> {
173174

174175
// when hitting the 'd' key again
175176
{
176-
app.process_events(&mut terminal, b"d".keys())?;
177+
app.process_events(new_test_terminal()?, b"d".keys())?;
177178

178179
assert_eq!(
179180
Some(2),
@@ -190,7 +191,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> {
190191

191192
// when hitting the 'd' key once again
192193
{
193-
app.process_events(&mut terminal, b"d".keys())?;
194+
app.process_events(new_test_terminal()?, b"d".keys())?;
194195

195196
assert_eq!(
196197
Some(1),
@@ -207,7 +208,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> {
207208
}
208209
// when hitting the spacebar (after moving up to the first entry)
209210
{
210-
app.process_events(&mut terminal, b"k ".keys())?;
211+
app.process_events(new_test_terminal()?, b"k ".keys())?;
211212

212213
assert_eq!(
213214
None,
@@ -226,7 +227,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> {
226227
// Marking
227228
{
228229
// select something
229-
app.process_events(&mut terminal, b" j ".keys())?;
230+
app.process_events(new_test_terminal()?, b" j ".keys())?;
230231
assert_eq!(
231232
Some(false),
232233
app.window.mark_pane.as_ref().map(|p| p.has_focus()),
@@ -240,7 +241,7 @@ fn simple_user_journey_read_only() -> Result<(), Error> {
240241
);
241242

242243
// when advancing the selection to the marker pane
243-
app.process_events(&mut terminal, b"\t".keys())?;
244+
app.process_events(new_test_terminal()?, b"\t".keys())?;
244245
{
245246
assert_eq!(
246247
Some(true),

src/interactive/app_test/journeys_with_writes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::interactive::app_test::utils::{
2-
initialized_app_and_terminal_from_paths, WritableFixture,
2+
initialized_app_and_terminal_from_paths, new_test_terminal, WritableFixture,
33
};
44
use failure::Error;
55
use pretty_assertions::assert_eq;
@@ -9,10 +9,10 @@ use termion::input::TermRead;
99
#[test]
1010
fn basic_user_journey_with_deletion() -> Result<(), Error> {
1111
let fixture = WritableFixture::from("sample-02");
12-
let (mut terminal, mut app) = initialized_app_and_terminal_from_paths(&[fixture.root.clone()])?;
12+
let (terminal, mut app) = initialized_app_and_terminal_from_paths(&[fixture.root.clone()])?;
1313

1414
// With a selection of items
15-
app.process_events(&mut terminal, b"doddd".keys())?;
15+
app.process_events(terminal, b"doddd".keys())?;
1616

1717
assert_eq!(
1818
app.window.mark_pane.as_ref().map(|p| p.marked().len()),
@@ -28,7 +28,7 @@ fn basic_user_journey_with_deletion() -> Result<(), Error> {
2828

2929
// When selecting the marker window and pressing the combination to delete entries
3030
app.process_events(
31-
&mut terminal,
31+
new_test_terminal()?,
3232
vec![Ok(Key::Char('\t')), Ok(Key::Ctrl('r'))].into_iter(),
3333
)?;
3434
assert_eq!(

src/interactive/app_test/utils.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub fn initialized_app_and_terminal_with_closure<P: AsRef<Path>>(
155155
fixture_paths: &[P],
156156
mut convert: impl FnMut(&Path) -> PathBuf,
157157
) -> Result<(Terminal<TestBackend>, TerminalApp), Error> {
158-
let mut terminal = Terminal::new(TestBackend::new(40, 20))?;
158+
let mut terminal = new_test_terminal()?;
159159
std::env::set_current_dir(Path::new(env!("CARGO_MANIFEST_DIR")))?;
160160

161161
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>>(
174174
Ok((terminal, app))
175175
}
176176

177+
pub fn new_test_terminal() -> std::io::Result<Terminal<TestBackend>> {
178+
Terminal::new(TestBackend::new(40, 20))
179+
}
180+
177181
pub fn initialized_app_and_terminal_from_paths(
178182
fixture_paths: &[PathBuf],
179183
) -> Result<(Terminal<TestBackend>, TerminalApp), Error> {

0 commit comments

Comments
 (0)