From 64a5ab632e0a30f2c95cbb6959b829962ce1c44a Mon Sep 17 00:00:00 2001 From: Phyfl <100218248+Phyfl@users.noreply.github.com> Date: Mon, 7 Oct 2024 22:30:29 +0200 Subject: [PATCH] Created tests for 4 cases of the xit operation --- helix-term/tests/test/commands/write.rs | 97 +++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/helix-term/tests/test/commands/write.rs b/helix-term/tests/test/commands/write.rs index bb3992d49..51ddd8e01 100644 --- a/helix-term/tests/test/commands/write.rs +++ b/helix-term/tests/test/commands/write.rs @@ -9,6 +9,103 @@ use helix_view::doc; use super::*; + +#[tokio::test(flavor = "multi_thread")] +async fn test_xit_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.:x"), + 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_xit_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"), 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_xit_wo_buffer_wo_path() -> anyhow::Result<()> { + + test_key_sequence( + &mut AppBuilder::new().build()?, + Some(format!(":x").as_ref()), + None, + true, + ) + .await?; + + //helpers::assert_file_has_content(&mut file, &LineFeedHandling::Native.apply("hello"))?; + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread")] +async fn test_xit_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(format!("itest:x").as_ref()), + None, + false + ) + .await?; + test_key_sequence(//try to write with path succeeds + &mut AppBuilder::new().build()?, + Some(format!("iMicCheck:x {}", 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()?;