@@ -1,5 +1,6 @@
2 io::{Read, Write},
2 io::{Read, Write},
3 time::Duration,
4 time::Duration,
@@ -21,7 +22,7 @@ async fn test_write() -> anyhow::Result<()> {
22 Config::default(),
23 Config::default(),
24− "ii can eat glass, it will not hurt me<ret><esc>:w<ret>",
25+ Some("ii can eat glass, it will not hurt me<ret><esc>:w<ret>"),
26 Some(Duration::from_millis(1000)),
27 Some(Duration::from_millis(1000)),
@@ -37,6 +38,41 @@ async fn test_write() -> anyhow::Result<()> {
42+async fn test_write_concurrent() -> anyhow::Result<()> {
43+ let mut file = tempfile::NamedTempFile::new().unwrap();
44+ let mut command = String::new();
45+ const RANGE: RangeInclusive<i32> = 1..=5000;
48+ let cmd = format!("%c{}<esc>:w<ret>", i);
49+ command.push_str(&cmd);
53+ &mut Application::new(
55+ files: vec![(file.path().to_path_buf(), Position::default())],
62+ Some(Duration::from_millis(10000)),
66+ file.as_file_mut().flush()?;
67+ file.as_file_mut().sync_all()?;
69+ let mut file_content = String::new();
70+ file.as_file_mut().read_to_string(&mut file_content)?;
71+ assert_eq!(RANGE.end().to_string(), file_content);
40#[tokio::test]
76#[tokio::test]
41async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
77async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
42 test_key_sequences(
78 test_key_sequences(
@@ -49,21 +85,21 @@ async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
53 Some(&|app| {
89 Some(&|app| {
54 let doc = doc!(app.editor);
90 let doc = doc!(app.editor);
55 assert!(!doc.is_modified());
91 assert!(!doc.is_modified());
59− "ihello<esc>",
95+ Some("ihello<esc>"),
60 Some(&|app| {
96 Some(&|app| {
61 let doc = doc!(app.editor);
97 let doc = doc!(app.editor);
62 assert!(doc.is_modified());
98 assert!(doc.is_modified());
66− ":w<ret>",
102+ Some(":w<ret>"),
67 Some(&|app| {
103 Some(&|app| {
68 assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
104 assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
@@ -86,7 +122,7 @@ async fn test_write_fail_new_path() -> anyhow::Result<()> {
86 &mut Application::new(Args::default(), Config::default())?,
122 &mut Application::new(Args::default(), Config::default())?,
90 Some(&|app| {
126 Some(&|app| {
91 let doc = doc!(app.editor);
127 let doc = doc!(app.editor);
92 assert_eq!(None, app.editor.get_status());
128 assert_eq!(None, app.editor.get_status());
@@ -94,7 +130,7 @@ async fn test_write_fail_new_path() -> anyhow::Result<()> {
97− ":w /foo<ret>",
133+ Some(":w /foo<ret>"),
98 Some(&|app| {
134 Some(&|app| {
99 let doc = doc!(app.editor);
135 let doc = doc!(app.editor);
100 assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
136 assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);