diff options
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/application.rs | 4 | ||||
-rw-r--r-- | helix-term/tests/test/commands.rs | 16 | ||||
-rw-r--r-- | helix-term/tests/test/helpers.rs | 14 | ||||
-rw-r--r-- | helix-term/tests/test/movement.rs | 11 | ||||
-rw-r--r-- | helix-term/tests/test/write.rs | 32 |
5 files changed, 21 insertions, 56 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 2790c9a4..48e9c275 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -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; } } diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 01f13c5c..0cd79bc7 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -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); @@ -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()); diff --git a/helix-term/tests/test/helpers.rs b/helix-term/tests/test/helpers.rs index 894fb674..8f2501e6 100644 --- a/helix-term/tests/test/helpers.rs +++ b/helix-term/tests/test/helpers.rs @@ -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}; @@ -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(), + ) +} diff --git a/helix-term/tests/test/movement.rs b/helix-term/tests/test/movement.rs index 5fb2ce25..088685df 100644 --- a/helix-term/tests/test/movement.rs +++ b/helix-term/tests/test/movement.rs @@ -1,5 +1,3 @@ -use helix_term::application::Application; - use super::*; #[tokio::test] @@ -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(); diff --git a/helix-term/tests/test/write.rs b/helix-term/tests/test/write.rs index d22b3125..39efa2ce 100644 --- a/helix-term/tests/test/write.rs +++ b/helix-term/tests/test/write.rs @@ -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, @@ -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, @@ -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, @@ -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, |