@@ -1,5 +1,6 @@
11use std::{
22 io::{Read, Write},
3+ ops::RangeInclusive,
34 time::Duration,
45};
56
@@ -21,7 +22,7 @@ async fn test_write() -> anyhow::Result<()> {
2122 },
2223 Config::default(),
2324 )?,
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>"),
2526 None,
2627 Some(Duration::from_millis(1000)),
2728 )
@@ -37,6 +38,41 @@ async fn test_write() -> anyhow::Result<()> {
3738 Ok(())
3839}
3940
41+#[tokio::test]
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;
46+
47+ for i in RANGE {
48+ let cmd = format!("%c{}<esc>:w<ret>", i);
49+ command.push_str(&cmd);
50+ }
51+
52+ test_key_sequence(
53+ &mut Application::new(
54+ Args {
55+ files: vec![(file.path().to_path_buf(), Position::default())],
56+ ..Default::default()
57+ },
58+ Config::default(),
59+ )?,
60+ Some(&command),
61+ None,
62+ Some(Duration::from_millis(10000)),
63+ )
64+ .await?;
65+
66+ file.as_file_mut().flush()?;
67+ file.as_file_mut().sync_all()?;
68+
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);
72+
73+ Ok(())
74+}
75+
4076#[tokio::test]
4177async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
4278 test_key_sequences(
@@ -49,21 +85,21 @@ async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
4985 )?,
5086 vec![
5187 (
52− "",
88+ None,
5389 Some(&|app| {
5490 let doc = doc!(app.editor);
5591 assert!(!doc.is_modified());
5692 }),
5793 ),
5894 (
59− "ihello<esc>",
95+ Some("ihello<esc>"),
6096 Some(&|app| {
6197 let doc = doc!(app.editor);
6298 assert!(doc.is_modified());
6399 }),
64100 ),
65101 (
66− ":w<ret>",
102+ Some(":w<ret>"),
67103 Some(&|app| {
68104 assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
69105
@@ -86,7 +122,7 @@ async fn test_write_fail_new_path() -> anyhow::Result<()> {
86122 &mut Application::new(Args::default(), Config::default())?,
87123 vec![
88124 (
89− "",
125+ None,
90126 Some(&|app| {
91127 let doc = doc!(app.editor);
92128 assert_eq!(None, app.editor.get_status());
@@ -94,7 +130,7 @@ async fn test_write_fail_new_path() -> anyhow::Result<()> {
94130 }),
95131 ),
96132 (
97− ":w /foo<ret>",
133+ Some(":w /foo<ret>"),
98134 Some(&|app| {
99135 let doc = doc!(app.editor);
100136 assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);