on master help sign in
factor new Application with file arg to function
665286cSkyler Hawthorne
helix-term/src/application.rs+1−3
@@ -239,11 +239,9 @@ impl Application {
239 self.last_render = Instant::now();
239 self.last_render = Instant::now();
240
240
241 loop {
241 loop {
242− if self.editor.should_close() {
242+ if !self.event_loop_until_idle(input_stream).await {
243 break;
243 break;
244 }
244 }
245−
246− self.event_loop_until_idle(input_stream).await;
247 }
245 }
248 }
246 }
249
247
helix-term/tests/test/commands.rs+2−14
@@ -13,13 +13,7 @@ async fn test_write_quit_fail() -> anyhow::Result<()> {
13 let file = helpers::new_readonly_tempfile()?;
13 let file = helpers::new_readonly_tempfile()?;
14
14
15 test_key_sequence(
15 test_key_sequence(
16− &mut Application::new(
16+ &mut helpers::app_with_file(file.path())?,
17− Args {
18− files: vec![(file.path().to_path_buf(), Position::default())],
19− ..Default::default()
20− },
21− Config::default(),
22− )?,
23 Some("ihello<esc>:wq<ret>"),
17 Some("ihello<esc>:wq<ret>"),
24 Some(&|app| {
18 Some(&|app| {
25 assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
19 assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
@@ -76,13 +70,7 @@ async fn test_buffer_close_concurrent() -> anyhow::Result<()> {
76 command.push_str(":buffer<minus>close<ret>");
70 command.push_str(":buffer<minus>close<ret>");
77
71
78 test_key_sequence(
72 test_key_sequence(
79− &mut Application::new(
73+ &mut helpers::app_with_file(file.path())?,
80− Args {
81− files: vec![(file.path().to_path_buf(), Position::default())],
82− ..Default::default()
83− },
84− Config::default(),
85− )?,
86 Some(&command),
74 Some(&command),
87 Some(&|app| {
75 Some(&|app| {
88 assert!(!app.editor.is_err(), "error: {:?}", app.editor.get_status());
76 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};
2
2
3use anyhow::bail;
3use anyhow::bail;
4use crossterm::event::{Event, KeyEvent};
4use crossterm::event::{Event, KeyEvent};
@@ -199,3 +199,15 @@ pub fn new_readonly_tempfile() -> anyhow::Result<NamedTempFile> {
199 file.as_file_mut().set_permissions(perms)?;
199 file.as_file_mut().set_permissions(perms)?;
200 Ok(file)
200 Ok(file)
201}
201}
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−
3use super::*;
1use super::*;
4
2
5#[tokio::test]
3#[tokio::test]
@@ -72,14 +70,7 @@ async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> {
72async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
70async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
73 let test = |content: &str, expected_sel: Selection| -> anyhow::Result<()> {
71 let test = |content: &str, expected_sel: Selection| -> anyhow::Result<()> {
74 let file = helpers::temp_file_with_contents(content)?;
72 let file = helpers::temp_file_with_contents(content)?;
75−
73+ let mut app = helpers::app_with_file(file.path())?;
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− )?;
83
74
84 let (view, doc) = helix_view::current!(app.editor);
75 let (view, doc) = helix_view::current!(app.editor);
85 let sel = doc.selection(view.id).clone();
76 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<()> {
14 let mut file = tempfile::NamedTempFile::new()?;
14 let mut file = tempfile::NamedTempFile::new()?;
15
15
16 test_key_sequence(
16 test_key_sequence(
17− &mut Application::new(
17+ &mut helpers::app_with_file(file.path())?,
18− Args {
19− files: vec![(file.path().to_path_buf(), Position::default())],
20− ..Default::default()
21− },
22− Config::default(),
23− )?,
24 Some("ii can eat glass, it will not hurt me<ret><esc>:w<ret>"),
18 Some("ii can eat glass, it will not hurt me<ret><esc>:w<ret>"),
25 None,
19 None,
26 false,
20 false,
@@ -46,13 +40,7 @@ async fn test_write_quit() -> anyhow::Result<()> {
46 let mut file = tempfile::NamedTempFile::new()?;
40 let mut file = tempfile::NamedTempFile::new()?;
47
41
48 test_key_sequence(
42 test_key_sequence(
49− &mut Application::new(
43+ &mut helpers::app_with_file(file.path())?,
50− Args {
51− files: vec![(file.path().to_path_buf(), Position::default())],
52− ..Default::default()
53− },
54− Config::default(),
55− )?,
56 Some("ii can eat glass, it will not hurt me<ret><esc>:wq<ret>"),
44 Some("ii can eat glass, it will not hurt me<ret><esc>:wq<ret>"),
57 None,
45 None,
58 true,
46 true,
@@ -86,13 +74,7 @@ async fn test_write_concurrent() -> anyhow::Result<()> {
86 }
74 }
87
75
88 test_key_sequence(
76 test_key_sequence(
89− &mut Application::new(
77+ &mut helpers::app_with_file(file.path())?,
90− Args {
91− files: vec![(file.path().to_path_buf(), Position::default())],
92− ..Default::default()
93− },
94− Config::default(),
95− )?,
96 Some(&command),
78 Some(&command),
97 None,
79 None,
98 false,
80 false,
@@ -115,13 +97,7 @@ async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
115 let file = helpers::new_readonly_tempfile()?;
97 let file = helpers::new_readonly_tempfile()?;
116
98
117 test_key_sequences(
99 test_key_sequences(
118− &mut Application::new(
100+ &mut helpers::app_with_file(file.path())?,
119− Args {
120− files: vec![(file.path().to_path_buf(), Position::default())],
121− ..Default::default()
122− },
123− Config::default(),
124− )?,
125 vec![
101 vec![
126 (
102 (
127 None,
103 None,