Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/tests/test/commands/write.rs')
| -rw-r--r-- | helix-term/tests/test/commands/write.rs | 222 |
1 files changed, 1 insertions, 221 deletions
diff --git a/helix-term/tests/test/commands/write.rs b/helix-term/tests/test/commands/write.rs index 4f44cd36..aba101e9 100644 --- a/helix-term/tests/test/commands/write.rs +++ b/helix-term/tests/test/commands/write.rs @@ -10,100 +10,6 @@ use helix_view::doc; use super::*; #[tokio::test(flavor = "multi_thread")] -async fn test_exit_w_buffer_w_path() -> anyhow::Result<()> { - let mut file = tempfile::NamedTempFile::new()?; - let mut app = helpers::AppBuilder::new() - .with_file(file.path(), None) - .build()?; - // Check for write operation on given path and edited buffer - test_key_sequence( - &mut app, - Some("iBecause of the obvious threat to untold numbers of citizens due to the crisis that is even now developing, this radio station will remain on the air day and night.<ret><esc>:x<ret>"), - None, - true, - ) - .await?; - - reload_file(&mut file).unwrap(); - let mut file_content = String::new(); - file.as_file_mut().read_to_string(&mut file_content)?; - - assert_eq!( - LineFeedHandling::Native.apply("Because of the obvious threat to untold numbers of citizens due to the crisis that is even now developing, this radio station will remain on the air day and night.\n"), - file_content - ); - - Ok(()) -} - -#[tokio::test(flavor = "multi_thread")] -async fn test_exit_wo_buffer_w_path() -> anyhow::Result<()> { - let mut file = tempfile::NamedTempFile::new()?; - let mut app = helpers::AppBuilder::new() - .with_file(file.path(), None) - .build()?; - - helpers::run_event_loop_until_idle(&mut app).await; - - file.as_file_mut() - .write_all("extremely important content".as_bytes())?; - file.as_file_mut().flush()?; - file.as_file_mut().sync_all()?; - - test_key_sequence(&mut app, Some(":x<ret>"), None, true).await?; - - reload_file(&mut file).unwrap(); - let mut file_content = String::new(); - file.read_to_string(&mut file_content)?; - // check that nothing is written to file - assert_eq!("extremely important content", file_content); - - Ok(()) -} - -#[tokio::test(flavor = "multi_thread")] -async fn test_exit_wo_buffer_wo_path() -> anyhow::Result<()> { - test_key_sequence( - &mut AppBuilder::new().build()?, - Some(":x<ret>"), - Some(&|app| { - assert!(!app.editor.is_err()); - }), - true, - ) - .await?; - - Ok(()) -} - -#[tokio::test(flavor = "multi_thread")] -async fn test_exit_w_buffer_wo_file() -> anyhow::Result<()> { - let mut file = tempfile::NamedTempFile::new()?; - test_key_sequence( - // try to write without destination - &mut AppBuilder::new().build()?, - Some("itest<esc>:x<ret>"), - None, - false, - ) - .await?; - test_key_sequence( - // try to write with path succeeds - &mut AppBuilder::new().build()?, - Some(format!("iMicCheck<esc>:x {}<ret>", file.path().to_string_lossy()).as_ref()), - Some(&|app| { - assert!(!app.editor.is_err()); - }), - true, - ) - .await?; - - helpers::assert_file_has_content(&mut file, &LineFeedHandling::Native.apply("MicCheck"))?; - - Ok(()) -} - -#[tokio::test(flavor = "multi_thread")] async fn test_write_quit_fail() -> anyhow::Result<()> { let file = helpers::new_readonly_tempfile()?; let mut app = helpers::AppBuilder::new() @@ -238,7 +144,7 @@ async fn test_overwrite_protection() -> anyhow::Result<()> { file.as_file_mut().flush()?; file.as_file_mut().sync_all()?; - test_key_sequence(&mut app, Some("iOverwriteData<esc>:x<ret>"), None, false).await?; + test_key_sequence(&mut app, Some(":x<ret>"), None, false).await?; reload_file(&mut file).unwrap(); let mut file_content = String::new(); @@ -515,50 +421,6 @@ async fn test_write_utf_bom_file() -> anyhow::Result<()> { } #[tokio::test(flavor = "multi_thread")] -async fn test_write_trim_trailing_whitespace() -> anyhow::Result<()> { - let mut file = tempfile::NamedTempFile::new()?; - let mut app = helpers::AppBuilder::new() - .with_config(Config { - editor: helix_view::editor::Config { - trim_trailing_whitespace: true, - ..Default::default() - }, - ..Default::default() - }) - .with_file(file.path(), None) - .with_input_text(LineFeedHandling::Native.apply("#[f|]#oo \n\n \nbar ")) - .build()?; - - test_key_sequence(&mut app, Some(":w<ret>"), None, false).await?; - - helpers::assert_file_has_content(&mut file, &LineFeedHandling::Native.apply("foo\n\n\nbar"))?; - - Ok(()) -} - -#[tokio::test(flavor = "multi_thread")] -async fn test_write_trim_final_newlines() -> anyhow::Result<()> { - let mut file = tempfile::NamedTempFile::new()?; - let mut app = helpers::AppBuilder::new() - .with_config(Config { - editor: helix_view::editor::Config { - trim_final_newlines: true, - ..Default::default() - }, - ..Default::default() - }) - .with_file(file.path(), None) - .with_input_text(LineFeedHandling::Native.apply("#[f|]#oo\n \n\n\n")) - .build()?; - - test_key_sequence(&mut app, Some(":w<ret>"), None, false).await?; - - helpers::assert_file_has_content(&mut file, &LineFeedHandling::Native.apply("foo\n \n"))?; - - Ok(()) -} - -#[tokio::test(flavor = "multi_thread")] async fn test_write_insert_final_newline_added_if_missing() -> anyhow::Result<()> { let mut file = tempfile::NamedTempFile::new()?; let mut app = helpers::AppBuilder::new() @@ -577,21 +439,6 @@ async fn test_write_insert_final_newline_added_if_missing() -> anyhow::Result<() } #[tokio::test(flavor = "multi_thread")] -async fn test_write_insert_final_newline_unchanged_if_empty() -> anyhow::Result<()> { - let mut file = tempfile::NamedTempFile::new()?; - let mut app = helpers::AppBuilder::new() - .with_file(file.path(), None) - .with_input_text("#[|]#") - .build()?; - - test_key_sequence(&mut app, Some(":w<ret>"), None, false).await?; - - helpers::assert_file_has_content(&mut file, "")?; - - Ok(()) -} - -#[tokio::test(flavor = "multi_thread")] async fn test_write_insert_final_newline_unchanged_if_not_missing() -> anyhow::Result<()> { let mut file = tempfile::NamedTempFile::new()?; let mut app = helpers::AppBuilder::new() @@ -866,70 +713,3 @@ async fn edit_file_with_content(file_content: &[u8]) -> anyhow::Result<()> { Ok(()) } - -#[tokio::test(flavor = "multi_thread")] -async fn test_move_file_when_given_dir_and_filename() -> anyhow::Result<()> { - let dir = tempfile::tempdir()?; - let source_file = tempfile::NamedTempFile::new_in(&dir)?; - let target_file = dir.path().join("new_name.ext"); - - let mut app = helpers::AppBuilder::new() - .with_file(source_file.path(), None) - .build()?; - - test_key_sequence( - &mut app, - Some(format!(":move {}<ret>", target_file.to_string_lossy()).as_ref()), - None, - false, - ) - .await?; - - assert!( - target_file.is_file(), - "target file '{}' should have been created", - target_file.display() - ); - assert!( - !source_file.path().exists(), - "Source file '{}' should have been removed", - source_file.path().display() - ); - - Ok(()) -} - -#[tokio::test(flavor = "multi_thread")] -async fn test_move_file_when_given_dir_only() -> anyhow::Result<()> { - let source_dir = tempfile::tempdir()?; - let target_dir = tempfile::tempdir()?; - let source_file = source_dir.path().join("file.ext"); - std::fs::File::create(&source_file)?; - - let mut app = helpers::AppBuilder::new() - .with_file(&source_file, None) - .build()?; - - test_key_sequence( - &mut app, - Some(format!(":move {}<ret>", target_dir.path().to_string_lossy()).as_ref()), - None, - false, - ) - .await?; - - let target_file = target_dir.path().join("file.ext"); - - assert!( - target_file.is_file(), - "target file '{}' should have been created", - target_file.display() - ); - assert!( - !source_file.exists(), - "Source file '{}' should have been removed", - source_file.display() - ); - - Ok(()) -} |