Skip to content

Commit

Permalink
Unit test moving lines and selections
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Gołąb committed Nov 8, 2022
1 parent 8011c44 commit d98a27e
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 1 deletion.
2 changes: 1 addition & 1 deletion helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ helix-dap = { version = "0.6", path = "../helix-dap" }
helix-loader = { version = "0.6", path = "../helix-loader" }

anyhow = "1"
once_cell = "1.15"
once_cell = "1.16"
itertools = "0.10.5"

which = "4.2"
Expand Down
157 changes: 157 additions & 0 deletions helix-term/tests/test/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,160 @@ async fn test_multi_selection_paste() -> 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-up>",
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-down>",
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-up>",
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-down><C-down>",
"aaaaaa\nbbbbbb\ncccccc\ndd#[|d]#ddd"
)).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-down>",
platform_line(indoc! {"
dddddd
#[|aaaaaa
bbbbbb
ccc]#ccc
eeeeee
"})
.as_str(),
)).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-up>",
platform_line(indoc! {"
bb#[bbbb
ccc|]#ccc
aaaaaa
dddddd
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-down>",
platform_line(indoc! {"
aaaaaa
cccccc
bb#[|b]#bbb
eeeeee
d#(dd|)#ddd
"})
.as_str(),
)).await?;

Ok(())
}

0 comments on commit d98a27e

Please sign in to comment.