aboutsummaryrefslogtreecommitdiff
path: root/helix-term/tests/integration/write.rs
diff options
context:
space:
mode:
authorSkyler Hawthorne2022-05-01 00:44:54 +0000
committerSkyler Hawthorne2022-06-19 03:54:03 +0000
commit07fc80aece221233b4a986b0c5a03e2056cc1307 (patch)
tree5165c2e33265cefa10081b77fb6436b4f08c8d26 /helix-term/tests/integration/write.rs
parentee705dcb3363aeb197f6125ab2f8285782333010 (diff)
tests for serialized writes
Diffstat (limited to 'helix-term/tests/integration/write.rs')
-rw-r--r--helix-term/tests/integration/write.rs79
1 files changed, 60 insertions, 19 deletions
diff --git a/helix-term/tests/integration/write.rs b/helix-term/tests/integration/write.rs
index 47e56288..27f97a45 100644
--- a/helix-term/tests/integration/write.rs
+++ b/helix-term/tests/integration/write.rs
@@ -1,9 +1,11 @@
use std::{
io::{Read, Write},
- ops::RangeInclusive,
+ time::Duration,
};
+use helix_core::diagnostic::Severity;
use helix_term::application::Application;
+use helix_view::doc;
use super::*;
@@ -21,6 +23,7 @@ async fn test_write() -> anyhow::Result<()> {
)?,
"ii can eat glass, it will not hurt me<ret><esc>:w<ret>",
None,
+ Some(Duration::from_millis(1000)),
)
.await?;
@@ -35,35 +38,73 @@ async fn test_write() -> anyhow::Result<()> {
}
#[tokio::test]
-async fn test_write_concurrent() -> anyhow::Result<()> {
- let mut file = tempfile::NamedTempFile::new().unwrap();
- let mut command = String::new();
- const RANGE: RangeInclusive<i32> = 1..=1000;
-
- for i in RANGE {
- let cmd = format!("%c{}<esc>:w<ret>", i);
- command.push_str(&cmd);
- }
-
- test_key_sequence(
+async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
+ test_key_sequences(
&mut Application::new(
Args {
- files: vec![(file.path().to_path_buf(), Position::default())],
+ files: vec![(PathBuf::from("/foo"), Position::default())],
..Default::default()
},
Config::default(),
)?,
- &command,
+ vec![
+ (
+ "",
+ Some(&|app| {
+ let doc = doc!(app.editor);
+ assert!(!doc.is_modified());
+ }),
+ ),
+ (
+ "ihello<esc>",
+ Some(&|app| {
+ let doc = doc!(app.editor);
+ assert!(doc.is_modified());
+ }),
+ ),
+ (
+ ":w<ret>",
+ Some(&|app| {
+ assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
+
+ let doc = doc!(app.editor);
+ assert!(doc.is_modified());
+ }),
+ ),
+ ],
None,
)
.await?;
- file.as_file_mut().flush()?;
- file.as_file_mut().sync_all()?;
+ Ok(())
+}
- let mut file_content = String::new();
- file.as_file_mut().read_to_string(&mut file_content)?;
- assert_eq!(RANGE.end().to_string(), file_content);
+#[tokio::test]
+#[ignore]
+async fn test_write_fail_new_path() -> anyhow::Result<()> {
+ test_key_sequences(
+ &mut Application::new(Args::default(), Config::default())?,
+ vec![
+ (
+ "",
+ Some(&|app| {
+ let doc = doc!(app.editor);
+ assert_eq!(None, app.editor.get_status());
+ assert_eq!(None, doc.path());
+ }),
+ ),
+ (
+ ":w /foo<ret>",
+ Some(&|app| {
+ let doc = doc!(app.editor);
+ assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
+ assert_eq!(None, doc.path());
+ }),
+ ),
+ ],
+ Some(Duration::from_millis(1000)),
+ )
+ .await?;
Ok(())
}