From 7cf650270c78238b5efd7ea4182205114f53540b Mon Sep 17 00:00:00 2001 From: sireliah Date: Wed, 1 May 2024 13:53:30 -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: JJ --- helix-term/tests/test/commands.rs | 166 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) (limited to 'helix-term/tests/test') diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 1172a798..9084bf63 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()?; -- cgit v1.2.3-70-g09d2