on master help sign in
factor new Application with file arg to function
commit665286c199b344c0bd65772156b5e460ff11d768 authorSkyler Hawthorne <skyler@dead10ck.com> dateFri 10 Jun 2022, 23:35 (4 years ago) parent65bf683
5 files changed+21−56
helix-term/src/application.rs+1−3 helix-term/tests/test/commands.rs+2−14 helix-term/tests/test/helpers.rs+13−1 helix-term/tests/test/movement.rs+1−10 helix-term/tests/test/write.rs+4−28
helix-term/src/application.rs+1−3
@@ -239,11 +239,9 @@ impl Application {
239239 self.last_render = Instant::now();
240240
241241 loop {
242− if self.editor.should_close() {
242+ if !self.event_loop_until_idle(input_stream).await {
243243 break;
244244 }
245−
246− self.event_loop_until_idle(input_stream).await;
247245 }
248246 }
249247
helix-term/tests/test/commands.rs+2−14
@@ -13,13 +13,7 @@ async fn test_write_quit_fail() -> anyhow::Result<()> {
1313 let file = helpers::new_readonly_tempfile()?;
1414
1515 test_key_sequence(
16− &mut Application::new(
17− Args {
18− files: vec![(file.path().to_path_buf(), Position::default())],
19− ..Default::default()
20− },
21− Config::default(),
22− )?,
16+ &mut helpers::app_with_file(file.path())?,
2317 Some("ihello<esc>:wq<ret>"),
2418 Some(&|app| {
2519 assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
@@ -76,13 +70,7 @@ async fn test_buffer_close_concurrent() -> anyhow::Result<()> {
7670 command.push_str(":buffer<minus>close<ret>");
7771
7872 test_key_sequence(
79− &mut Application::new(
80− Args {
81− files: vec![(file.path().to_path_buf(), Position::default())],
82− ..Default::default()
83− },
84− Config::default(),
85− )?,
73+ &mut helpers::app_with_file(file.path())?,
8674 Some(&command),
8775 Some(&|app| {
8876 assert!(!app.editor.is_err(), "error: {:?}", app.editor.get_status());
helix-term/tests/test/helpers.rs+13−1
@@ -1,4 +1,4 @@
1−use std::{io::Write, time::Duration};
1+use std::{io::Write, path::PathBuf, time::Duration};
22
33use anyhow::bail;
44use crossterm::event::{Event, KeyEvent};
@@ -199,3 +199,15 @@ pub fn new_readonly_tempfile() -> anyhow::Result<NamedTempFile> {
199199 file.as_file_mut().set_permissions(perms)?;
200200 Ok(file)
201201}
202+
203+/// Creates a new Application with default config that opens the given file
204+/// path
205+pub fn app_with_file<P: Into<PathBuf>>(path: P) -> anyhow::Result<Application> {
206+ Application::new(
207+ Args {
208+ files: vec![(path.into(), helix_core::Position::default())],
209+ ..Default::default()
210+ },
211+ Config::default(),
212+ )
213+}
helix-term/tests/test/movement.rs+1−10
@@ -1,5 +1,3 @@
1−use helix_term::application::Application;
2−
31use super::*;
42
53#[tokio::test]
@@ -72,14 +70,7 @@ async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> {
7270async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
7371 let test = |content: &str, expected_sel: Selection| -> anyhow::Result<()> {
7472 let file = helpers::temp_file_with_contents(content)?;
75−
76− let mut app = Application::new(
77− Args {
78− files: vec![(file.path().to_path_buf(), Position::default())],
79− ..Default::default()
80− },
81− Config::default(),
82− )?;
73+ let mut app = helpers::app_with_file(file.path())?;
8374
8475 let (view, doc) = helix_view::current!(app.editor);
8576 let sel = doc.selection(view.id).clone();
helix-term/tests/test/write.rs+4−28
@@ -14,13 +14,7 @@ async fn test_write() -> anyhow::Result<()> {
1414 let mut file = tempfile::NamedTempFile::new()?;
1515
1616 test_key_sequence(
17− &mut Application::new(
18− Args {
19− files: vec![(file.path().to_path_buf(), Position::default())],
20− ..Default::default()
21− },
22− Config::default(),
23− )?,
17+ &mut helpers::app_with_file(file.path())?,
2418 Some("ii can eat glass, it will not hurt me<ret><esc>:w<ret>"),
2519 None,
2620 false,
@@ -46,13 +40,7 @@ async fn test_write_quit() -> anyhow::Result<()> {
4640 let mut file = tempfile::NamedTempFile::new()?;
4741
4842 test_key_sequence(
49− &mut Application::new(
50− Args {
51− files: vec![(file.path().to_path_buf(), Position::default())],
52− ..Default::default()
53− },
54− Config::default(),
55− )?,
43+ &mut helpers::app_with_file(file.path())?,
5644 Some("ii can eat glass, it will not hurt me<ret><esc>:wq<ret>"),
5745 None,
5846 true,
@@ -86,13 +74,7 @@ async fn test_write_concurrent() -> anyhow::Result<()> {
8674 }
8775
8876 test_key_sequence(
89− &mut Application::new(
90− Args {
91− files: vec![(file.path().to_path_buf(), Position::default())],
92− ..Default::default()
93− },
94− Config::default(),
95− )?,
77+ &mut helpers::app_with_file(file.path())?,
9678 Some(&command),
9779 None,
9880 false,
@@ -115,13 +97,7 @@ async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
11597 let file = helpers::new_readonly_tempfile()?;
11698
11799 test_key_sequences(
118− &mut Application::new(
119− Args {
120− files: vec![(file.path().to_path_buf(), Position::default())],
121− ..Default::default()
122− },
123− Config::default(),
124− )?,
100+ &mut helpers::app_with_file(file.path())?,
125101 vec![
126102 (
127103 None,