diff options
author | JJ | 2023-11-01 02:41:44 +0000 |
---|---|---|
committer | JJ | 2023-11-01 04:08:53 +0000 |
commit | 696fa18edece20f10d8b276728c55ad712be1da9 (patch) | |
tree | 8d70c0bfde06c781146b6646834613d8b37c0e29 /helix-term/tests/test/commands.rs | |
parent | 7260812a720336111dc4643c9852e34820745338 (diff) |
Add support for moving selections above and below
ref: https://github.com/helix-editor/helix/issues/2245
ref: https://github.com/helix-editor/helix/pull/4545
Co-authored-by: sireliah <sajuukk@gmail.com>
Diffstat (limited to 'helix-term/tests/test/commands.rs')
-rw-r--r-- | helix-term/tests/test/commands.rs | 186 |
1 files changed, 176 insertions, 10 deletions
diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index b3e13551..a6c1c956 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -97,6 +97,172 @@ async fn test_selection_duplication() -> anyhow::Result<()> { Ok(()) } +// Line selection movement tests + +#[tokio::test(flavor = "multi_thread")] +async fn test_move_selection_single_selection_up() -> anyhow::Result<()> { + test(( + platform_line(indoc! {" + aaaaaa + bbbbbb + cc#[|c]#ccc + dddddd + "}) + .as_str(), + "<C-k>", + platform_line(indoc! {" + aaaaaa + cc#[|c]#ccc + bbbbbb + dddddd + "}) + .as_str(), + )) + .await?; + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread")] +async fn test_move_selection_single_selection_down() -> anyhow::Result<()> { + test(( + platform_line(indoc! {" + aa#[|a]#aaa + bbbbbb + cccccc + dddddd + "}) + .as_str(), + "<C-j>", + platform_line(indoc! {" + bbbbbb + aa#[|a]#aaa + cccccc + dddddd + "}) + .as_str(), + )) + .await?; + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread")] +async fn test_move_selection_single_selection_top_up() -> anyhow::Result<()> { + // if already on top of the file and going up, nothing should change + test(( + platform_line(indoc! {" + aa#[|a]#aaa + bbbbbb + cccccc + dddddd"}) + .as_str(), + "<C-k>", + platform_line(indoc! {" + aa#[|a]#aaa + bbbbbb + cccccc + dddddd"}) + .as_str(), + )) + .await?; + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread")] +async fn test_move_selection_single_selection_bottom_down() -> anyhow::Result<()> { + // If going down on the bottom line, nothing should change + // Note that platform_line is not used here, because it inserts trailing + // linebreak, making it impossible to test + test(( + "aaaaaa\nbbbbbb\ncccccc\ndd#[|d]#ddd", + "<C-j><C-j>", + "aaaaaa\nbbbbbb\ncccccc\ndd#[|d]#ddd", + )) + .await?; + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread")] +async fn test_move_selection_block_up() -> anyhow::Result<()> { + test(( + platform_line(indoc! {" + aaaaaa + bb#[bbbb + ccc|]#ccc + dddddd + eeeeee + "}) + .as_str(), + "<C-k>", + platform_line(indoc! {" + bb#[bbbb + ccc|]#ccc + aaaaaa + dddddd + eeeeee + "}) + .as_str(), + )) + .await?; + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread")] +async fn test_move_selection_block_down() -> anyhow::Result<()> { + test(( + platform_line(indoc! {" + #[|aaaaaa + bbbbbb + ccc]#ccc + dddddd + eeeeee + "}) + .as_str(), + "<C-j>", + platform_line(indoc! {" + dddddd + #[|aaaaaa + bbbbbb + ccc]#ccc + eeeeee + "}) + .as_str(), + )) + .await?; + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread")] +async fn test_move_two_cursors_down() -> anyhow::Result<()> { + test(( + platform_line(indoc! {" + aaaaaa + bb#[|b]#bbb + cccccc + d#(dd|)#ddd + eeeeee + "}) + .as_str(), + "<C-j>", + platform_line(indoc! {" + aaaaaa + cccccc + bb#[|b]#bbb + eeeeee + d#(dd|)#ddd + "}) + .as_str(), + )) + .await?; + + Ok(()) +} + #[tokio::test(flavor = "multi_thread")] async fn test_goto_file_impl() -> anyhow::Result<()> { let file = tempfile::NamedTempFile::new()?; @@ -188,11 +354,11 @@ async fn test_multi_selection_shell_commands() -> anyhow::Result<()> { "|echo foo<ret>", platform_line(indoc! {"\ #[|foo\n]# - + #(|foo\n)# - + #(|foo\n)# - + "}), )) .await?; @@ -226,11 +392,11 @@ async fn test_multi_selection_shell_commands() -> anyhow::Result<()> { "<A-!>echo foo<ret>", platform_line(indoc! {"\ lorem#[|foo\n]# - + ipsum#(|foo\n)# - + dolor#(|foo\n)# - + "}), )) .await?; @@ -274,14 +440,14 @@ async fn test_extend_line() -> anyhow::Result<()> { #[l|]#orem ipsum dolor - + "}), "x2x", platform_line(indoc! {"\ #[lorem ipsum dolor\n|]# - + "}), )) .await?; @@ -291,13 +457,13 @@ async fn test_extend_line() -> anyhow::Result<()> { platform_line(indoc! {"\ #[l|]#orem ipsum - + "}), "2x", platform_line(indoc! {"\ #[lorem ipsum\n|]# - + "}), )) .await?; |