@@ -128,6 +128,52 @@ async fn test_write_fail_mod_flag() -> anyhow::Result<()> {
132+async fn test_write_scratch_to_new_path() -> anyhow::Result<()> {
133+ let mut file = tempfile::NamedTempFile::new()?;
136+ &mut Application::new(Args::default(), Config::default())?,
137+ Some(format!("ihello<esc>:w {}<ret>", file.path().to_string_lossy()).as_ref()),
139+ assert!(!app.editor.is_err());
141+ let mut docs: Vec<_> = app.editor.documents().collect();
142+ assert_eq!(1, docs.len());
144+ let doc = docs.pop().unwrap();
145+ assert_eq!(Some(&file.path().to_path_buf()), doc.path());
151+ helpers::assert_file_has_content(file.as_file_mut(), &helpers::platform_line("hello"))?;
157+async fn test_write_scratch_no_path_fails() -> anyhow::Result<()> {
158+ helpers::test_key_sequence_with_input_text(
160+ ("#[\n|]#", "ihello<esc>:w<ret>", "hello#[\n|]#"),
162+ assert!(app.editor.is_err());
164+ let mut docs: Vec<_> = app.editor.documents().collect();
165+ assert_eq!(1, docs.len());
167+ let doc = docs.pop().unwrap();
168+ assert_eq!(None, doc.path());
131#[tokio::test]
177#[tokio::test]
132async fn test_write_new_path() -> anyhow::Result<()> {
178async fn test_write_new_path() -> anyhow::Result<()> {
133 let mut file1 = tempfile::NamedTempFile::new().unwrap();
179 let mut file1 = tempfile::NamedTempFile::new().unwrap();
@@ -164,24 +210,15 @@ async fn test_write_new_path() -> anyhow::Result<()> {
167− file1.as_file_mut().flush()?;
213+ helpers::assert_file_has_content(
168− file1.as_file_mut().sync_all()?;
214+ file1.as_file_mut(),
169− file2.as_file_mut().flush()?;
215+ &helpers::platform_line("i can eat glass, it will not hurt me\n"),
170− file2.as_file_mut().sync_all()?;
216+ )?;
172− let mut file1_content = String::new();
218+ helpers::assert_file_has_content(
173− file1.as_file_mut().read_to_string(&mut file1_content)?;
175− helpers::platform_line("i can eat glass, it will not hurt me\n"),
179− let mut file2_content = String::new();
180− file2.as_file_mut().read_to_string(&mut file2_content)?;
219+ file2.as_file_mut(),
182− helpers::platform_line("i can eat glass, it will not hurt me\n"),
220+ &helpers::platform_line("i can eat glass, it will not hurt me\n"),