factor new Application with file arg to function

pull/2359/head
Skyler Hawthorne 2 years ago
parent 65bf6836b7
commit 665286c199

@ -239,11 +239,9 @@ impl Application {
self.last_render = Instant::now(); self.last_render = Instant::now();
loop { loop {
if self.editor.should_close() { if !self.event_loop_until_idle(input_stream).await {
break; break;
} }
self.event_loop_until_idle(input_stream).await;
} }
} }

@ -13,13 +13,7 @@ async fn test_write_quit_fail() -> anyhow::Result<()> {
let file = helpers::new_readonly_tempfile()?; let file = helpers::new_readonly_tempfile()?;
test_key_sequence( test_key_sequence(
&mut Application::new( &mut helpers::app_with_file(file.path())?,
Args {
files: vec![(file.path().to_path_buf(), Position::default())],
..Default::default()
},
Config::default(),
)?,
Some("ihello<esc>:wq<ret>"), Some("ihello<esc>:wq<ret>"),
Some(&|app| { Some(&|app| {
assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1); 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>"); command.push_str(":buffer<minus>close<ret>");
test_key_sequence( test_key_sequence(
&mut Application::new( &mut helpers::app_with_file(file.path())?,
Args {
files: vec![(file.path().to_path_buf(), Position::default())],
..Default::default()
},
Config::default(),
)?,
Some(&command), Some(&command),
Some(&|app| { Some(&|app| {
assert!(!app.editor.is_err(), "error: {:?}", app.editor.get_status()); assert!(!app.editor.is_err(), "error: {:?}", app.editor.get_status());

@ -1,4 +1,4 @@
use std::{io::Write, time::Duration}; use std::{io::Write, path::PathBuf, time::Duration};
use anyhow::bail; use anyhow::bail;
use crossterm::event::{Event, KeyEvent}; use crossterm::event::{Event, KeyEvent};
@ -199,3 +199,15 @@ pub fn new_readonly_tempfile() -> anyhow::Result<NamedTempFile> {
file.as_file_mut().set_permissions(perms)?; file.as_file_mut().set_permissions(perms)?;
Ok(file) 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(),
)
}

@ -1,5 +1,3 @@
use helix_term::application::Application;
use super::*; use super::*;
#[tokio::test] #[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<()> { async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
let test = |content: &str, expected_sel: Selection| -> anyhow::Result<()> { let test = |content: &str, expected_sel: Selection| -> anyhow::Result<()> {
let file = helpers::temp_file_with_contents(content)?; let file = helpers::temp_file_with_contents(content)?;
let mut app = helpers::app_with_file(file.path())?;
let mut app = Application::new(
Args {
files: vec![(file.path().to_path_buf(), Position::default())],
..Default::default()
},
Config::default(),
)?;
let (view, doc) = helix_view::current!(app.editor); let (view, doc) = helix_view::current!(app.editor);
let sel = doc.selection(view.id).clone(); let sel = doc.selection(view.id).clone();

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

Loading…
Cancel
Save