2022-10-28 05:31:28 +04:00
|
|
|
use helix_term::application::Application;
|
2022-05-01 04:44:54 +04:00
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
2024-10-07 19:20:33 +04:00
|
|
|
mod insert;
|
2022-08-17 05:28:41 +04:00
|
|
|
mod movement;
|
2023-02-17 22:50:00 +04:00
|
|
|
mod write;
|
2022-07-05 02:51:15 +04:00
|
|
|
|
2022-10-21 08:28:29 +04:00
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
2022-07-05 02:51:15 +04:00
|
|
|
async fn test_selection_duplication() -> anyhow::Result<()> {
|
|
|
|
// Forward
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2022-07-05 02:51:15 +04:00
|
|
|
#[lo|]#rem
|
|
|
|
ipsum
|
|
|
|
dolor
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2022-07-05 02:51:15 +04:00
|
|
|
"CC",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2022-07-05 02:51:15 +04:00
|
|
|
#(lo|)#rem
|
|
|
|
#(ip|)#sum
|
|
|
|
#[do|]#lor
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2022-07-05 02:51:15 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// Backward
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2022-07-05 02:51:15 +04:00
|
|
|
#[|lo]#rem
|
|
|
|
ipsum
|
|
|
|
dolor
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2022-07-05 02:51:15 +04:00
|
|
|
"CC",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2022-07-05 02:51:15 +04:00
|
|
|
#(|lo)#rem
|
|
|
|
#(|ip)#sum
|
|
|
|
#[|do]#lor
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2022-07-05 02:51:15 +04:00
|
|
|
))
|
|
|
|
.await?;
|
2023-02-09 18:28:33 +04:00
|
|
|
|
|
|
|
// Copy the selection to previous line, skipping the first line in the file
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-02-09 18:28:33 +04:00
|
|
|
test
|
|
|
|
#[testitem|]#
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-02-09 18:28:33 +04:00
|
|
|
"<A-C>",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-02-09 18:28:33 +04:00
|
|
|
test
|
|
|
|
#[testitem|]#
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-02-09 18:28:33 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// Copy the selection to previous line, including the first line in the file
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-02-09 18:28:33 +04:00
|
|
|
test
|
|
|
|
#[test|]#
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-02-09 18:28:33 +04:00
|
|
|
"<A-C>",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-02-09 18:28:33 +04:00
|
|
|
#[test|]#
|
|
|
|
#(test|)#
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-02-09 18:28:33 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// Copy the selection to next line, skipping the last line in the file
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-02-09 18:28:33 +04:00
|
|
|
#[testitem|]#
|
|
|
|
test
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-02-09 18:28:33 +04:00
|
|
|
"C",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-02-09 18:28:33 +04:00
|
|
|
#[testitem|]#
|
|
|
|
test
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-02-09 18:28:33 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// Copy the selection to next line, including the last line in the file
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-02-09 18:28:33 +04:00
|
|
|
#[test|]#
|
|
|
|
test
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-02-09 18:28:33 +04:00
|
|
|
"C",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-02-09 18:28:33 +04:00
|
|
|
#(test|)#
|
|
|
|
#[test|]#
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-02-09 18:28:33 +04:00
|
|
|
))
|
|
|
|
.await?;
|
2022-07-05 02:51:15 +04:00
|
|
|
Ok(())
|
|
|
|
}
|
2022-10-28 05:31:28 +04:00
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_goto_file_impl() -> anyhow::Result<()> {
|
|
|
|
let file = tempfile::NamedTempFile::new()?;
|
|
|
|
|
|
|
|
fn match_paths(app: &Application, matches: Vec<&str>) -> usize {
|
|
|
|
app.editor
|
|
|
|
.documents()
|
|
|
|
.filter_map(|d| d.path()?.file_name())
|
|
|
|
.filter(|n| matches.iter().any(|m| *m == n.to_string_lossy()))
|
|
|
|
.count()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Single selection
|
|
|
|
test_key_sequence(
|
|
|
|
&mut AppBuilder::new().with_file(file.path(), None).build()?,
|
|
|
|
Some("ione.js<esc>%gf"),
|
|
|
|
Some(&|app| {
|
|
|
|
assert_eq!(1, match_paths(app, vec!["one.js"]));
|
|
|
|
}),
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// Multiple selection
|
|
|
|
test_key_sequence(
|
|
|
|
&mut AppBuilder::new().with_file(file.path(), None).build()?,
|
|
|
|
Some("ione.js<ret>two.js<esc>%<A-s>gf"),
|
|
|
|
Some(&|app| {
|
|
|
|
assert_eq!(2, match_paths(app, vec!["one.js", "two.js"]));
|
|
|
|
}),
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// Cursor on first quote
|
|
|
|
test_key_sequence(
|
|
|
|
&mut AppBuilder::new().with_file(file.path(), None).build()?,
|
|
|
|
Some("iimport 'one.js'<esc>B;gf"),
|
|
|
|
Some(&|app| {
|
|
|
|
assert_eq!(1, match_paths(app, vec!["one.js"]));
|
|
|
|
}),
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// Cursor on last quote
|
|
|
|
test_key_sequence(
|
|
|
|
&mut AppBuilder::new().with_file(file.path(), None).build()?,
|
|
|
|
Some("iimport 'one.js'<esc>bgf"),
|
|
|
|
Some(&|app| {
|
|
|
|
assert_eq!(1, match_paths(app, vec!["one.js"]));
|
|
|
|
}),
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
2024-04-07 01:27:29 +04:00
|
|
|
// ';' is behind the path
|
|
|
|
test_key_sequence(
|
|
|
|
&mut AppBuilder::new().with_file(file.path(), None).build()?,
|
|
|
|
Some("iimport 'one.js';<esc>B;gf"),
|
|
|
|
Some(&|app| {
|
|
|
|
assert_eq!(1, match_paths(app, vec!["one.js"]));
|
|
|
|
}),
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// allow numeric values in path
|
|
|
|
test_key_sequence(
|
|
|
|
&mut AppBuilder::new().with_file(file.path(), None).build()?,
|
|
|
|
Some("iimport 'one123.js'<esc>B;gf"),
|
|
|
|
Some(&|app| {
|
|
|
|
assert_eq!(1, match_paths(app, vec!["one123.js"]));
|
|
|
|
}),
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
2022-10-28 05:31:28 +04:00
|
|
|
Ok(())
|
|
|
|
}
|
2022-11-06 18:56:45 +04:00
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_multi_selection_paste() -> anyhow::Result<()> {
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2022-11-06 18:56:45 +04:00
|
|
|
#[|lorem]#
|
|
|
|
#(|ipsum)#
|
|
|
|
#(|dolor)#
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2022-11-06 18:56:45 +04:00
|
|
|
"yp",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2022-11-06 18:56:45 +04:00
|
|
|
lorem#[|lorem]#
|
|
|
|
ipsum#(|ipsum)#
|
|
|
|
dolor#(|dolor)#
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2022-11-06 18:56:45 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2022-11-14 04:45:52 +04:00
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_multi_selection_shell_commands() -> anyhow::Result<()> {
|
|
|
|
// pipe
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2022-11-14 04:45:52 +04:00
|
|
|
#[|lorem]#
|
|
|
|
#(|ipsum)#
|
|
|
|
#(|dolor)#
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2022-11-14 04:45:52 +04:00
|
|
|
"|echo foo<ret>",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2024-07-13 05:44:48 +04:00
|
|
|
#[|foo]#
|
|
|
|
#(|foo)#
|
|
|
|
#(|foo)#"
|
|
|
|
},
|
2022-11-14 04:45:52 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// insert-output
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2022-11-14 04:45:52 +04:00
|
|
|
#[|lorem]#
|
|
|
|
#(|ipsum)#
|
|
|
|
#(|dolor)#
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2022-11-14 04:45:52 +04:00
|
|
|
"!echo foo<ret>",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2024-07-13 05:44:48 +04:00
|
|
|
#[|foo]#lorem
|
|
|
|
#(|foo)#ipsum
|
|
|
|
#(|foo)#dolor
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2022-11-14 04:45:52 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// append-output
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2022-11-14 04:45:52 +04:00
|
|
|
#[|lorem]#
|
|
|
|
#(|ipsum)#
|
|
|
|
#(|dolor)#
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2022-11-14 04:45:52 +04:00
|
|
|
"<A-!>echo foo<ret>",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2024-07-13 05:44:48 +04:00
|
|
|
lorem#[|foo]#
|
|
|
|
ipsum#(|foo)#
|
|
|
|
dolor#(|foo)#
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2022-11-14 04:45:52 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2022-11-23 18:57:09 +04:00
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_undo_redo() -> anyhow::Result<()> {
|
2022-11-23 19:35:07 +04:00
|
|
|
// A jumplist selection is created at a point which is undone.
|
|
|
|
//
|
|
|
|
// * 2[<space> Add two newlines at line start. We're now on line 3.
|
|
|
|
// * <C-s> Save the selection on line 3 in the jumplist.
|
|
|
|
// * u Undo the two newlines. We're now on line 1.
|
|
|
|
// * <C-o><C-i> Jump forward an back again in the jumplist. This would panic
|
|
|
|
// if the jumplist were not being updated correctly.
|
2024-03-31 16:12:17 +04:00
|
|
|
test((
|
|
|
|
"#[|]#",
|
|
|
|
"2[<space><C-s>u<C-o><C-i>",
|
|
|
|
"#[|]#",
|
|
|
|
LineFeedHandling::AsIs,
|
|
|
|
))
|
|
|
|
.await?;
|
2022-11-23 19:35:07 +04:00
|
|
|
|
2022-11-23 18:57:09 +04:00
|
|
|
// A jumplist selection is passed through an edit and then an undo and then a redo.
|
|
|
|
//
|
|
|
|
// * [<space> Add a newline at line start. We're now on line 2.
|
|
|
|
// * <C-s> Save the selection on line 2 in the jumplist.
|
|
|
|
// * kd Delete line 1. The jumplist selection should be adjusted to the new line 1.
|
|
|
|
// * uU Undo and redo the `kd` edit.
|
|
|
|
// * <C-o> Jump back in the jumplist. This would panic if the jumplist were not being
|
|
|
|
// updated correctly.
|
|
|
|
// * <C-i> Jump forward to line 1.
|
2024-03-31 16:12:17 +04:00
|
|
|
test((
|
|
|
|
"#[|]#",
|
|
|
|
"[<space><C-s>kduU<C-o><C-i>",
|
|
|
|
"#[|]#",
|
|
|
|
LineFeedHandling::AsIs,
|
|
|
|
))
|
|
|
|
.await?;
|
2022-11-23 18:57:09 +04:00
|
|
|
|
2022-11-23 23:02:00 +04:00
|
|
|
// In this case we 'redo' manually to ensure that the transactions are composing correctly.
|
2024-03-31 16:12:17 +04:00
|
|
|
test((
|
|
|
|
"#[|]#",
|
|
|
|
"[<space>u[<space>u",
|
|
|
|
"#[|]#",
|
|
|
|
LineFeedHandling::AsIs,
|
|
|
|
))
|
|
|
|
.await?;
|
2022-11-23 23:02:00 +04:00
|
|
|
|
2022-11-23 18:57:09 +04:00
|
|
|
Ok(())
|
|
|
|
}
|
2022-12-31 18:23:55 +04:00
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_extend_line() -> anyhow::Result<()> {
|
|
|
|
// extend with line selected then count
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2022-12-31 18:23:55 +04:00
|
|
|
#[l|]#orem
|
|
|
|
ipsum
|
|
|
|
dolor
|
|
|
|
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2022-12-31 18:23:55 +04:00
|
|
|
"x2x",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2022-12-31 18:23:55 +04:00
|
|
|
#[lorem
|
|
|
|
ipsum
|
2022-09-17 17:34:56 +04:00
|
|
|
dolor\n|]#
|
|
|
|
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2022-12-31 18:23:55 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// extend with count on partial selection
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2022-12-31 18:23:55 +04:00
|
|
|
#[l|]#orem
|
|
|
|
ipsum
|
|
|
|
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2022-12-31 18:23:55 +04:00
|
|
|
"2x",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2022-12-31 18:23:55 +04:00
|
|
|
#[lorem
|
2022-09-17 17:34:56 +04:00
|
|
|
ipsum\n|]#
|
|
|
|
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2022-12-31 18:23:55 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2023-02-03 18:24:46 +04:00
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_character_info() -> anyhow::Result<()> {
|
|
|
|
// UTF-8, single byte
|
|
|
|
test_key_sequence(
|
|
|
|
&mut helpers::AppBuilder::new().build()?,
|
|
|
|
Some("ih<esc>h:char<ret>"),
|
|
|
|
Some(&|app| {
|
|
|
|
assert_eq!(
|
|
|
|
r#""h" (U+0068) Dec 104 Hex 68"#,
|
|
|
|
app.editor.get_status().unwrap().0
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// UTF-8, multi-byte
|
|
|
|
test_key_sequence(
|
|
|
|
&mut helpers::AppBuilder::new().build()?,
|
|
|
|
Some("ië<esc>h:char<ret>"),
|
|
|
|
Some(&|app| {
|
|
|
|
assert_eq!(
|
|
|
|
r#""ë" (U+0065 U+0308) Hex 65 + cc 88"#,
|
|
|
|
app.editor.get_status().unwrap().0
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// Multiple characters displayed as one, escaped characters
|
|
|
|
test_key_sequence(
|
|
|
|
&mut helpers::AppBuilder::new().build()?,
|
|
|
|
Some(":line<minus>ending crlf<ret>:char<ret>"),
|
|
|
|
Some(&|app| {
|
|
|
|
assert_eq!(
|
|
|
|
r#""\r\n" (U+000d U+000a) Hex 0d + 0a"#,
|
|
|
|
app.editor.get_status().unwrap().0
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// Non-UTF-8
|
|
|
|
test_key_sequence(
|
|
|
|
&mut helpers::AppBuilder::new().build()?,
|
|
|
|
Some(":encoding ascii<ret>ih<esc>h:char<ret>"),
|
|
|
|
Some(&|app| {
|
|
|
|
assert_eq!(r#""h" Dec 104 Hex 68"#, app.editor.get_status().unwrap().0);
|
|
|
|
}),
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2023-02-17 01:15:06 +04:00
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_delete_char_backward() -> anyhow::Result<()> {
|
|
|
|
// don't panic when deleting overlapping ranges
|
2024-03-31 16:12:17 +04:00
|
|
|
test(("#(x|)# #[x|]#", "c<space><backspace><esc>", "#[\n|]#")).await?;
|
2023-02-17 01:15:06 +04:00
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
"#( |)##( |)#a#( |)#axx#[x|]#a",
|
2023-02-17 01:15:06 +04:00
|
|
|
"li<backspace><esc>",
|
2024-03-31 16:12:17 +04:00
|
|
|
"#(a|)##(|a)#xx#[|a]#",
|
2023-02-17 01:15:06 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_delete_word_backward() -> anyhow::Result<()> {
|
|
|
|
// don't panic when deleting overlapping ranges
|
2024-03-31 16:12:17 +04:00
|
|
|
test(("fo#[o|]#ba#(r|)#", "a<C-w><esc>", "#[\n|]#")).await?;
|
2023-02-17 01:15:06 +04:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_delete_word_forward() -> anyhow::Result<()> {
|
|
|
|
// don't panic when deleting overlapping ranges
|
2024-03-31 16:12:17 +04:00
|
|
|
test(("fo#[o|]#b#(|ar)#", "i<A-d><esc>", "fo#[\n|]#")).await?;
|
2023-02-17 01:15:06 +04:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2023-02-20 19:31:26 +04:00
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_delete_char_forward() -> anyhow::Result<()> {
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-02-20 19:31:26 +04:00
|
|
|
#[abc|]#def
|
|
|
|
#(abc|)#ef
|
|
|
|
#(abc|)#f
|
|
|
|
#(abc|)#
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-02-20 19:31:26 +04:00
|
|
|
"a<del><esc>",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-02-20 19:31:26 +04:00
|
|
|
#[abc|]#ef
|
|
|
|
#(abc|)#f
|
|
|
|
#(abc|)#
|
|
|
|
#(abc|)#
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-02-20 19:31:26 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2023-06-08 21:11:40 +04:00
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_insert_with_indent() -> anyhow::Result<()> {
|
2024-03-31 16:12:17 +04:00
|
|
|
const INPUT: &str = indoc! { "
|
|
|
|
#[f|]#n foo() {
|
|
|
|
if let Some(_) = None {
|
2023-06-08 21:11:40 +04:00
|
|
|
|
2024-03-31 16:12:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-06-08 21:11:40 +04:00
|
|
|
|
2024-03-31 16:12:17 +04:00
|
|
|
fn bar() {
|
2023-06-08 21:11:40 +04:00
|
|
|
|
2024-03-31 16:12:17 +04:00
|
|
|
}
|
|
|
|
"
|
|
|
|
};
|
2023-06-08 21:11:40 +04:00
|
|
|
|
|
|
|
// insert_at_line_start
|
|
|
|
test((
|
|
|
|
INPUT,
|
|
|
|
":lang rust<ret>%<A-s>I",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! { "
|
|
|
|
#[f|]#n foo() {
|
|
|
|
#(i|)#f let Some(_) = None {
|
|
|
|
#(\n|)#
|
|
|
|
#(}|)#
|
|
|
|
#( |)#
|
|
|
|
#(}|)#
|
|
|
|
#(\n|)#
|
|
|
|
#(f|)#n bar() {
|
|
|
|
#(\n|)#
|
|
|
|
#(}|)#
|
|
|
|
"
|
|
|
|
},
|
2023-06-08 21:11:40 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// insert_at_line_end
|
|
|
|
test((
|
|
|
|
INPUT,
|
|
|
|
":lang rust<ret>%<A-s>A",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! { "
|
|
|
|
fn foo() {#[\n|]#
|
|
|
|
if let Some(_) = None {#(\n|)#
|
|
|
|
#(\n|)#
|
|
|
|
}#(\n|)#
|
|
|
|
#(\n|)#
|
|
|
|
}#(\n|)#
|
|
|
|
#(\n|)#
|
|
|
|
fn bar() {#(\n|)#
|
|
|
|
#(\n|)#
|
|
|
|
}#(\n|)#
|
|
|
|
"
|
|
|
|
},
|
2023-06-08 21:11:40 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2023-12-06 19:19:54 +04:00
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_join_selections() -> anyhow::Result<()> {
|
|
|
|
// normal join
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-12-06 19:19:54 +04:00
|
|
|
#[a|]#bc
|
|
|
|
def
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-12-06 19:19:54 +04:00
|
|
|
"J",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-12-06 19:19:54 +04:00
|
|
|
#[a|]#bc def
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-12-06 19:19:54 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// join with empty line
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-12-06 19:19:54 +04:00
|
|
|
#[a|]#bc
|
|
|
|
|
|
|
|
def
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-12-06 19:19:54 +04:00
|
|
|
"JJ",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-12-06 19:19:54 +04:00
|
|
|
#[a|]#bc def
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-12-06 19:19:54 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// join with additional space in non-empty line
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-12-06 19:19:54 +04:00
|
|
|
#[a|]#bc
|
|
|
|
|
|
|
|
def
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-12-06 19:19:54 +04:00
|
|
|
"JJ",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2023-12-06 19:19:54 +04:00
|
|
|
#[a|]#bc def
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2023-12-06 19:19:54 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2024-03-02 18:05:58 +04:00
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_join_selections_space() -> anyhow::Result<()> {
|
|
|
|
// join with empty lines panic
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2024-03-02 18:05:58 +04:00
|
|
|
#[a
|
|
|
|
|
|
|
|
b
|
|
|
|
|
|
|
|
c
|
|
|
|
|
|
|
|
d
|
|
|
|
|
|
|
|
e|]#
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2024-03-02 18:05:58 +04:00
|
|
|
"<A-J>",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2024-03-02 18:05:58 +04:00
|
|
|
a#[ |]#b#( |)#c#( |)#d#( |)#e
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2024-03-02 18:05:58 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// normal join
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2024-03-02 18:05:58 +04:00
|
|
|
#[a|]#bc
|
|
|
|
def
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2024-03-02 18:05:58 +04:00
|
|
|
"<A-J>",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2024-03-02 18:05:58 +04:00
|
|
|
abc#[ |]#def
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2024-03-02 18:05:58 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// join with empty line
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2024-03-02 18:05:58 +04:00
|
|
|
#[a|]#bc
|
|
|
|
|
|
|
|
def
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2024-03-02 18:05:58 +04:00
|
|
|
"<A-J>",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2024-03-02 18:05:58 +04:00
|
|
|
#[a|]#bc
|
|
|
|
def
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2024-03-02 18:05:58 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// join with additional space in non-empty line
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2024-03-02 18:05:58 +04:00
|
|
|
#[a|]#bc
|
|
|
|
|
|
|
|
def
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2024-03-02 18:05:58 +04:00
|
|
|
"<A-J><A-J>",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2024-03-02 18:05:58 +04:00
|
|
|
abc#[ |]#def
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2024-03-02 18:05:58 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// join with retained trailing spaces
|
|
|
|
test((
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2024-03-02 18:05:58 +04:00
|
|
|
#[aaa
|
|
|
|
|
|
|
|
bb
|
|
|
|
|
|
|
|
c |]#
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2024-03-02 18:05:58 +04:00
|
|
|
"<A-J>",
|
2024-03-31 16:12:17 +04:00
|
|
|
indoc! {"\
|
2024-03-02 18:05:58 +04:00
|
|
|
aaa #[ |]#bb #( |)#c
|
2024-03-31 16:12:17 +04:00
|
|
|
"},
|
2024-03-02 18:05:58 +04:00
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2024-04-18 02:57:57 +04:00
|
|
|
|
2024-09-22 21:16:24 +04:00
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_join_selections_comment() -> anyhow::Result<()> {
|
|
|
|
test((
|
|
|
|
indoc! {"\
|
|
|
|
/// #[a|]#bc
|
|
|
|
/// def
|
|
|
|
"},
|
|
|
|
":lang rust<ret>J",
|
|
|
|
indoc! {"\
|
|
|
|
/// #[a|]#bc def
|
|
|
|
"},
|
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
// Only join if the comment token matches the previous line.
|
|
|
|
test((
|
|
|
|
indoc! {"\
|
|
|
|
#[| // a
|
|
|
|
// b
|
|
|
|
/// c
|
|
|
|
/// d
|
|
|
|
e
|
|
|
|
/// f
|
|
|
|
// g]#
|
|
|
|
"},
|
|
|
|
":lang rust<ret>J",
|
|
|
|
indoc! {"\
|
|
|
|
#[| // a b /// c d e f // g]#
|
|
|
|
"},
|
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2024-04-18 02:57:57 +04:00
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_read_file() -> anyhow::Result<()> {
|
|
|
|
let mut file = tempfile::NamedTempFile::new()?;
|
|
|
|
let contents_to_read = "some contents";
|
|
|
|
let output_file = helpers::temp_file_with_contents(contents_to_read)?;
|
|
|
|
|
|
|
|
test_key_sequence(
|
|
|
|
&mut helpers::AppBuilder::new()
|
|
|
|
.with_file(file.path(), None)
|
|
|
|
.build()?,
|
|
|
|
Some(&format!(":r {:?}<ret><esc>:w<ret>", output_file.path())),
|
|
|
|
Some(&|app| {
|
|
|
|
assert!(!app.editor.is_err(), "error: {:?}", app.editor.get_status());
|
|
|
|
}),
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
let expected_contents = LineFeedHandling::Native.apply(contents_to_read);
|
|
|
|
helpers::assert_file_has_content(&mut file, &expected_contents)?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2024-04-09 19:29:54 +04:00
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn surround_delete() -> anyhow::Result<()> {
|
|
|
|
// Test `surround_delete` when head < anchor
|
|
|
|
test(("(#[| ]#)", "mdm", "#[| ]#")).await?;
|
|
|
|
test(("(#[| ]#)", "md(", "#[| ]#")).await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn surround_replace_ts() -> anyhow::Result<()> {
|
|
|
|
const INPUT: &str = r#"\
|
|
|
|
fn foo() {
|
|
|
|
if let Some(_) = None {
|
|
|
|
todo!("f#[|o]#o)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#;
|
|
|
|
test((
|
|
|
|
INPUT,
|
|
|
|
":lang rust<ret>mrm'",
|
|
|
|
r#"\
|
|
|
|
fn foo() {
|
|
|
|
if let Some(_) = None {
|
|
|
|
todo!('f#[|o]#o)');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
test((
|
|
|
|
INPUT,
|
|
|
|
":lang rust<ret>3mrm[",
|
|
|
|
r#"\
|
|
|
|
fn foo() {
|
|
|
|
if let Some(_) = None [
|
|
|
|
todo!("f#[|o]#o)");
|
|
|
|
]
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
test((
|
|
|
|
INPUT,
|
|
|
|
":lang rust<ret>2mrm{",
|
|
|
|
r#"\
|
|
|
|
fn foo() {
|
|
|
|
if let Some(_) = None {
|
|
|
|
todo!{"f#[|o]#o)"};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
2024-06-10 19:07:43 +04:00
|
|
|
test((
|
|
|
|
indoc! {"\
|
|
|
|
#[a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
d
|
|
|
|
e|]#
|
|
|
|
f
|
|
|
|
"},
|
|
|
|
"s\\n<ret>r,",
|
|
|
|
"a#[,|]#b#(,|)#c#(,|)#d#(,|)#e\nf\n",
|
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
2024-04-09 19:29:54 +04:00
|
|
|
Ok(())
|
|
|
|
}
|