| 1 |
use super::*; |
| 2 |
|
| 3 |
use helix_stdx::path; |
| 4 |
|
| 5 |
#[tokio::test(flavor = "multi_thread")] |
| 6 |
async fn test_split_write_quit_all() -> anyhow::Result<()> { |
| 7 |
let mut file1 = tempfile::NamedTempFile::new()?; |
| 8 |
let mut file2 = tempfile::NamedTempFile::new()?; |
| 9 |
let mut file3 = tempfile::NamedTempFile::new()?; |
| 10 |
|
| 11 |
let mut app = helpers::AppBuilder::new() |
| 12 |
.with_file(file1.path(), None) |
| 13 |
.build()?; |
| 14 |
|
| 15 |
test_key_sequences( |
| 16 |
&mut app, |
| 17 |
vec![ |
| 18 |
( |
| 19 |
Some(&format!( |
| 20 |
"ihello1<esc>:sp<ret>:o {}<ret>ihello2<esc>:sp<ret>:o {}<ret>ihello3<esc>", |
| 21 |
file2.path().to_string_lossy(), |
| 22 |
file3.path().to_string_lossy() |
| 23 |
)), |
| 24 |
Some(&|app| { |
| 25 |
let docs: Vec<_> = app.editor.documents().collect(); |
| 26 |
assert_eq!(3, docs.len()); |
| 27 |
|
| 28 |
let doc1 = docs |
| 29 |
.iter() |
| 30 |
.find(|doc| doc.path().unwrap() == &path::normalize(file1.path())) |
| 31 |
.unwrap(); |
| 32 |
|
| 33 |
assert_eq!("hello1", doc1.text().to_string()); |
| 34 |
|
| 35 |
let doc2 = docs |
| 36 |
.iter() |
| 37 |
.find(|doc| doc.path().unwrap() == &path::normalize(file2.path())) |
| 38 |
.unwrap(); |
| 39 |
|
| 40 |
assert_eq!("hello2", doc2.text().to_string()); |
| 41 |
|
| 42 |
let doc3 = docs |
| 43 |
.iter() |
| 44 |
.find(|doc| doc.path().unwrap() == &path::normalize(file3.path())) |
| 45 |
.unwrap(); |
| 46 |
|
| 47 |
assert_eq!("hello3", doc3.text().to_string()); |
| 48 |
|
| 49 |
helpers::assert_status_not_error(&app.editor); |
| 50 |
assert_eq!(3, app.editor.tree.views().count()); |
| 51 |
}), |
| 52 |
), |
| 53 |
( |
| 54 |
Some(":wqa<ret>"), |
| 55 |
Some(&|app| { |
| 56 |
helpers::assert_status_not_error(&app.editor); |
| 57 |
assert_eq!(0, app.editor.tree.views().count()); |
| 58 |
}), |
| 59 |
), |
| 60 |
], |
| 61 |
true, |
| 62 |
) |
| 63 |
.await?; |
| 64 |
|
| 65 |
helpers::assert_file_has_content(&mut file1, &LineFeedHandling::Native.apply("hello1"))?; |
| 66 |
helpers::assert_file_has_content(&mut file2, &LineFeedHandling::Native.apply("hello2"))?; |
| 67 |
helpers::assert_file_has_content(&mut file3, &LineFeedHandling::Native.apply("hello3"))?; |
| 68 |
|
| 69 |
Ok(()) |
| 70 |
} |
| 71 |
|
| 72 |
#[tokio::test(flavor = "multi_thread")] |
| 73 |
async fn test_split_write_quit_same_file() -> anyhow::Result<()> { |
| 74 |
let mut file = tempfile::NamedTempFile::new()?; |
| 75 |
let mut app = helpers::AppBuilder::new() |
| 76 |
.with_file(file.path(), None) |
| 77 |
.build()?; |
| 78 |
|
| 79 |
test_key_sequences( |
| 80 |
&mut app, |
| 81 |
vec![ |
| 82 |
( |
| 83 |
Some("O<esc>ihello<esc>:sp<ret>ogoodbye<esc>"), |
| 84 |
Some(&|app| { |
| 85 |
assert_eq!(2, app.editor.tree.views().count()); |
| 86 |
helpers::assert_status_not_error(&app.editor); |
| 87 |
|
| 88 |
let mut docs: Vec<_> = app.editor.documents().collect(); |
| 89 |
assert_eq!(1, docs.len()); |
| 90 |
|
| 91 |
let doc = docs.pop().unwrap(); |
| 92 |
|
| 93 |
assert_eq!( |
| 94 |
LineFeedHandling::Native.apply("hello\ngoodbye"), |
| 95 |
doc.text().to_string() |
| 96 |
); |
| 97 |
|
| 98 |
assert!(doc.is_modified()); |
| 99 |
}), |
| 100 |
), |
| 101 |
( |
| 102 |
Some(":wq<ret>"), |
| 103 |
Some(&|app| { |
| 104 |
helpers::assert_status_not_error(&app.editor); |
| 105 |
assert_eq!(1, app.editor.tree.views().count()); |
| 106 |
|
| 107 |
let mut docs: Vec<_> = app.editor.documents().collect(); |
| 108 |
assert_eq!(1, docs.len()); |
| 109 |
|
| 110 |
let doc = docs.pop().unwrap(); |
| 111 |
|
| 112 |
assert_eq!( |
| 113 |
LineFeedHandling::Native.apply("hello\ngoodbye"), |
| 114 |
doc.text().to_string() |
| 115 |
); |
| 116 |
|
| 117 |
assert!(!doc.is_modified()); |
| 118 |
}), |
| 119 |
), |
| 120 |
], |
| 121 |
false, |
| 122 |
) |
| 123 |
.await?; |
| 124 |
|
| 125 |
helpers::assert_file_has_content(&mut file, &LineFeedHandling::Native.apply("hello\ngoodbye"))?; |
| 126 |
|
| 127 |
Ok(()) |
| 128 |
} |
| 129 |
|
| 130 |
#[tokio::test(flavor = "multi_thread")] |
| 131 |
async fn test_changes_in_splits_apply_to_all_views() -> anyhow::Result<()> { |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
test(( |
| 152 |
"#[|]#", |
| 153 |
"<C-w>v[<space><C-s><C-w>wkd<C-w>qd", |
| 154 |
"#[|]#", |
| 155 |
LineFeedHandling::AsIs, |
| 156 |
)) |
| 157 |
.await?; |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
test(( |
| 163 |
"#[|]#", |
| 164 |
"[<space>[<space>[<space><C-w>vuuu<C-w>wUUU<C-w>quuu", |
| 165 |
"#[|]#", |
| 166 |
LineFeedHandling::AsIs, |
| 167 |
)) |
| 168 |
.await?; |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
test(( |
| 189 |
"#[|]#", |
| 190 |
"3[<space><C-w>v<C-s><C-w>wuu3[<space><C-w>q%d", |
| 191 |
"#[|]#", |
| 192 |
LineFeedHandling::AsIs, |
| 193 |
)) |
| 194 |
.await?; |
| 195 |
|
| 196 |
Ok(()) |
| 197 |
} |
| 198 |
|
| 199 |
#[tokio::test(flavor = "multi_thread")] |
| 200 |
async fn test_changes_in_splits_jumplist_sync() -> anyhow::Result<()> { |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
test(( |
| 208 |
"#[test|]#", |
| 209 |
"<C-w>sgf<C-w>wd<C-w>w<C-o><C-w>qd", |
| 210 |
"#[|]#", |
| 211 |
LineFeedHandling::AsIs, |
| 212 |
)) |
| 213 |
.await?; |
| 214 |
|
| 215 |
Ok(()) |
| 216 |
} |
| 217 |
|
| 218 |
#[tokio::test(flavor = "multi_thread")] |
| 219 |
async fn test_reload_all_with_split_jumplist() -> anyhow::Result<()> { |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
use std::io::Write; |
| 239 |
let mut file = tempfile::NamedTempFile::new()?; |
| 240 |
|
| 241 |
|
| 242 |
file.write_all(b"line1\nline2\nline3\n")?; |
| 243 |
file.flush()?; |
| 244 |
|
| 245 |
let mut app = helpers::AppBuilder::new() |
| 246 |
.with_file(file.path(), None) |
| 247 |
.build()?; |
| 248 |
|
| 249 |
test_key_sequence( |
| 250 |
&mut app, |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
Some("<C-w>s]<space>%2Gms/:rla<ret>%J<C-w>q"), |
| 255 |
Some(&|app| { |
| 256 |
helpers::assert_status_not_error(&app.editor); |
| 257 |
}), |
| 258 |
false, |
| 259 |
) |
| 260 |
.await?; |
| 261 |
|
| 262 |
Ok(()) |
| 263 |
} |