Skip to content

Commit

Permalink
factor new Application with file arg to function
Browse files Browse the repository at this point in the history
  • Loading branch information
dead10ck committed Jun 14, 2022
1 parent fed42c4 commit 68c42a0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 56 deletions.
4 changes: 1 addition & 3 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,9 @@ impl Application {
self.last_render = Instant::now();

loop {
if self.editor.should_close() {
if !self.event_loop_until_idle(input_stream).await {
break;
}

self.event_loop_until_idle(input_stream).await;
}
}

Expand Down
16 changes: 2 additions & 14 deletions helix-term/tests/test/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ async fn test_write_quit_fail() -> anyhow::Result<()> {
let file = helpers::new_readonly_tempfile()?;

test_key_sequence(
&mut Application::new(
Args {
files: vec![(file.path().to_path_buf(), Position::default())],
..Default::default()
},
Config::default(),
)?,
&mut helpers::app_with_file(file.path())?,
Some("ihello<esc>:wq<ret>"),
Some(&|app| {
assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
Expand Down Expand Up @@ -76,13 +70,7 @@ async fn test_buffer_close_concurrent() -> anyhow::Result<()> {
command.push_str(":buffer<minus>close<ret>");

test_key_sequence(
&mut Application::new(
Args {
files: vec![(file.path().to_path_buf(), Position::default())],
..Default::default()
},
Config::default(),
)?,
&mut helpers::app_with_file(file.path())?,
Some(&command),
Some(&|app| {
assert!(!app.editor.is_err(), "error: {:?}", app.editor.get_status());
Expand Down
14 changes: 13 additions & 1 deletion helix-term/tests/test/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{io::Write, time::Duration};
use std::{io::Write, path::PathBuf, time::Duration};

use anyhow::bail;
use crossterm::event::{Event, KeyEvent};
Expand Down Expand Up @@ -199,3 +199,15 @@ pub fn new_readonly_tempfile() -> anyhow::Result<NamedTempFile> {
file.as_file_mut().set_permissions(perms)?;
Ok(file)
}

/// Creates a new Application with default config that opens the given file
/// path
pub fn app_with_file<P: Into<PathBuf>>(path: P) -> anyhow::Result<Application> {
Application::new(
Args {
files: vec![(path.into(), helix_core::Position::default())],
..Default::default()
},
Config::default(),
)
}
11 changes: 1 addition & 10 deletions helix-term/tests/test/movement.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use helix_term::application::Application;

use super::*;

#[tokio::test]
Expand Down Expand Up @@ -72,14 +70,7 @@ async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> {
async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
let test = |content: &str, expected_sel: Selection| -> anyhow::Result<()> {
let file = helpers::temp_file_with_contents(content)?;

let mut app = Application::new(
Args {
files: vec![(file.path().to_path_buf(), Position::default())],
..Default::default()
},
Config::default(),
)?;
let mut app = helpers::app_with_file(file.path())?;

let (view, doc) = helix_view::current!(app.editor);
let sel = doc.selection(view.id).clone();
Expand Down
32 changes: 4 additions & 28 deletions helix-term/tests/test/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ async fn test_write() -> anyhow::Result<()> {
let mut file = tempfile::NamedTempFile::new()?;

test_key_sequence(
&mut Application::new(
Args {
files: vec![(file.path().to_path_buf(), Position::default())],
..Default::default()
},
Config::default(),
)?,
&mut helpers::app_with_file(file.path())?,
Some("ii can eat glass, it will not hurt me<ret><esc>:w<ret>"),
None,
false,
Expand All @@ -46,13 +40,7 @@ async fn test_write_quit() -> anyhow::Result<()> {
let mut file = tempfile::NamedTempFile::new()?;

test_key_sequence(
&mut Application::new(
Args {
files: vec![(file.path().to_path_buf(), Position::default())],
..Default::default()
},
Config::default(),
)?,
&mut helpers::app_with_file(file.path())?,
Some("ii can eat glass, it will not hurt me<ret><esc>:wq<ret>"),
None,
true,
Expand Down Expand Up @@ -86,13 +74,7 @@ async fn test_write_concurrent() -> anyhow::Result<()> {
}

test_key_sequence(
&mut Application::new(
Args {
files: vec![(file.path().to_path_buf(), Position::default())],
..Default::default()
},
Config::default(),
)?,
&mut helpers::app_with_file(file.path())?,
Some(&command),
None,
false,
Expand All @@ -115,13 +97,7 @@ async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
let file = helpers::new_readonly_tempfile()?;

test_key_sequences(
&mut Application::new(
Args {
files: vec![(file.path().to_path_buf(), Position::default())],
..Default::default()
},
Config::default(),
)?,
&mut helpers::app_with_file(file.path())?,
vec![
(
None,
Expand Down

0 comments on commit 68c42a0

Please sign in to comment.