From 696fa18edece20f10d8b276728c55ad712be1da9 Mon Sep 17 00:00:00 2001 From: JJ Date: Tue, 31 Oct 2023 19:41:44 -0700 Subject: 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 --- helix-term/tests/test/commands.rs | 186 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 176 insertions(+), 10 deletions(-) (limited to 'helix-term/tests') 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(), + "", + 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(), + "", + 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(), + "", + 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", + "", + "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(), + "", + 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(), + "", + 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(), + "", + 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", platform_line(indoc! {"\ #[|foo\n]# - + #(|foo\n)# - + #(|foo\n)# - + "}), )) .await?; @@ -226,11 +392,11 @@ async fn test_multi_selection_shell_commands() -> anyhow::Result<()> { "echo foo", 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?; -- cgit v1.2.3-70-g09d2