on master help sign in
factor write command tests to own module
commit8c5ec95ac0a8535060b9e0545e4c46f57aeccbfd authorSkyler Hawthorne <skyler@dead10ck.com> dateFri 17 Feb 2023, 13:50 (4 years ago) parent78613ac
3 files changed+93−95
helix-term/tests/integration.rs−1 helix-term/tests/test/commands.rs+1−92 helix-term/tests/test/write.rs → helix-term/tests/test/commands/write.rs+92−2
helix-term/tests/integration.rs−1
@@ -23,5 +23,4 @@ mod test {
2323 mod movement;
2424 mod prompt;
2525 mod splits;
26− mod write;
2726}
helix-term/tests/test/commands.rs+1−92
@@ -1,99 +1,8 @@
1−use std::ops::RangeInclusive;
2−
3−use helix_core::diagnostic::Severity;
41use helix_term::application::Application;
52
63use super::*;
74
8−#[tokio::test(flavor = "multi_thread")]
9−async fn test_write_quit_fail() -> anyhow::Result<()> {
10− let file = helpers::new_readonly_tempfile()?;
11− let mut app = helpers::AppBuilder::new()
12− .with_file(file.path(), None)
13− .build()?;
14−
15− test_key_sequence(
16− &mut app,
17− Some("ihello<esc>:wq<ret>"),
18− Some(&|app| {
19− let mut docs: Vec<_> = app.editor.documents().collect();
20− assert_eq!(1, docs.len());
21−
22− let doc = docs.pop().unwrap();
23− assert_eq!(Some(file.path()), doc.path().map(PathBuf::as_path));
24− assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
25− }),
26− false,
27− )
28− .await?;
29−
30− Ok(())
31−}
32−
33−#[tokio::test(flavor = "multi_thread")]
34−async fn test_buffer_close_concurrent() -> anyhow::Result<()> {
35− test_key_sequences(
36− &mut helpers::AppBuilder::new().build()?,
37− vec![
38− (
39− None,
40− Some(&|app| {
41− assert_eq!(1, app.editor.documents().count());
42− assert!(!app.editor.is_err());
43− }),
44− ),
45− (
46− Some("ihello<esc>:new<ret>"),
47− Some(&|app| {
48− assert_eq!(2, app.editor.documents().count());
49− assert!(!app.editor.is_err());
50− }),
51− ),
52− (
53− Some(":buffer<minus>close<ret>"),
54− Some(&|app| {
55− assert_eq!(1, app.editor.documents().count());
56− assert!(!app.editor.is_err());
57− }),
58− ),
59− ],
60− false,
61− )
62− .await?;
63−
64− // verify if writes are queued up, it finishes them before closing the buffer
65− let mut file = tempfile::NamedTempFile::new()?;
66− let mut command = String::new();
67− const RANGE: RangeInclusive<i32> = 1..=1000;
68−
69− for i in RANGE {
70− let cmd = format!("%c{}<esc>:w!<ret>", i);
71− command.push_str(&cmd);
72− }
73−
74− command.push_str(":buffer<minus>close<ret>");
75−
76− let mut app = helpers::AppBuilder::new()
77− .with_file(file.path(), None)
78− .build()?;
79−
80− test_key_sequence(
81− &mut app,
82− Some(&command),
83− Some(&|app| {
84− assert!(!app.editor.is_err(), "error: {:?}", app.editor.get_status());
85−
86− let doc = app.editor.document_by_path(file.path());
87− assert!(doc.is_none(), "found doc: {:?}", doc);
88− }),
89− false,
90− )
91− .await?;
92−
93− helpers::assert_file_has_content(file.as_file_mut(), &RANGE.end().to_string())?;
94−
95− Ok(())
96−}
5+mod write;
976
987#[tokio::test(flavor = "multi_thread")]
998async fn test_selection_duplication() -> anyhow::Result<()> {
helix-term/tests/test/write.rs → helix-term/tests/test/commands/write.rsrenamed+92−2
@@ -1,5 +1,5 @@
11use std::{
2− io::{Read, Seek, SeekFrom, Write},
2+ io::{Read, Seek, Write},
33 ops::RangeInclusive,
44};
55
@@ -8,6 +8,96 @@ use helix_view::doc;
88
99use super::*;
1010
11+#[tokio::test(flavor = "multi_thread")]
12+async fn test_write_quit_fail() -> anyhow::Result<()> {
13+ let file = helpers::new_readonly_tempfile()?;
14+ let mut app = helpers::AppBuilder::new()
15+ .with_file(file.path(), None)
16+ .build()?;
17+
18+ test_key_sequence(
19+ &mut app,
20+ Some("ihello<esc>:wq<ret>"),
21+ Some(&|app| {
22+ let mut docs: Vec<_> = app.editor.documents().collect();
23+ assert_eq!(1, docs.len());
24+
25+ let doc = docs.pop().unwrap();
26+ assert_eq!(Some(file.path()), doc.path().map(PathBuf::as_path));
27+ assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
28+ }),
29+ false,
30+ )
31+ .await?;
32+
33+ Ok(())
34+}
35+
36+#[tokio::test(flavor = "multi_thread")]
37+async fn test_buffer_close_concurrent() -> anyhow::Result<()> {
38+ test_key_sequences(
39+ &mut helpers::AppBuilder::new().build()?,
40+ vec![
41+ (
42+ None,
43+ Some(&|app| {
44+ assert_eq!(1, app.editor.documents().count());
45+ assert!(!app.editor.is_err());
46+ }),
47+ ),
48+ (
49+ Some("ihello<esc>:new<ret>"),
50+ Some(&|app| {
51+ assert_eq!(2, app.editor.documents().count());
52+ assert!(!app.editor.is_err());
53+ }),
54+ ),
55+ (
56+ Some(":buffer<minus>close<ret>"),
57+ Some(&|app| {
58+ assert_eq!(1, app.editor.documents().count());
59+ assert!(!app.editor.is_err());
60+ }),
61+ ),
62+ ],
63+ false,
64+ )
65+ .await?;
66+
67+ // verify if writes are queued up, it finishes them before closing the buffer
68+ let mut file = tempfile::NamedTempFile::new()?;
69+ let mut command = String::new();
70+ const RANGE: RangeInclusive<i32> = 1..=1000;
71+
72+ for i in RANGE {
73+ let cmd = format!("%c{}<esc>:w!<ret>", i);
74+ command.push_str(&cmd);
75+ }
76+
77+ command.push_str(":buffer<minus>close<ret>");
78+
79+ let mut app = helpers::AppBuilder::new()
80+ .with_file(file.path(), None)
81+ .build()?;
82+
83+ test_key_sequence(
84+ &mut app,
85+ Some(&command),
86+ Some(&|app| {
87+ assert!(!app.editor.is_err(), "error: {:?}", app.editor.get_status());
88+
89+ let doc = app.editor.document_by_path(file.path());
90+ assert!(doc.is_none(), "found doc: {:?}", doc);
91+ }),
92+ false,
93+ )
94+ .await?;
95+
96+ helpers::assert_file_has_content(file.as_file_mut(), &RANGE.end().to_string())?;
97+
98+ Ok(())
99+}
100+
11101#[tokio::test(flavor = "multi_thread")]
12102async fn test_write() -> anyhow::Result<()> {
13103 let mut file = tempfile::NamedTempFile::new()?;
@@ -57,7 +147,7 @@ async fn test_overwrite_protection() -> anyhow::Result<()> {
57147 file.as_file_mut().flush()?;
58148 file.as_file_mut().sync_all()?;
59149
60− file.seek(SeekFrom::Start(0))?;
150+ file.rewind()?;
61151 let mut file_content = String::new();
62152 file.as_file_mut().read_to_string(&mut file_content)?;
63153