mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 09:26:19 +04:00
Created tests for 4 cases of the xit operation
This commit is contained in:
parent
205b5167b6
commit
64a5ab632e
@ -9,6 +9,103 @@
|
||||
|
||||
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.<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_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<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_xit_wo_buffer_wo_path() -> anyhow::Result<()> {
|
||||
|
||||
test_key_sequence(
|
||||
&mut AppBuilder::new().build()?,
|
||||
Some(format!(":x<ret>").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<esc>:x<ret>").as_ref()),
|
||||
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()?;
|
||||
|
Loading…
Reference in New Issue
Block a user