From 3458b7b0375a39d77d4285ffc4efc6561ae55102 Mon Sep 17 00:00:00 2001 From: Andrew Browne Date: Thu, 5 Jun 2025 21:43:39 -0700 Subject: [PATCH] Add unit tests for paste_all_selections_(before|after). --- helix-term/tests/test/commands.rs | 1 + .../test/commands/paste_all_selections.rs | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 helix-term/tests/test/commands/paste_all_selections.rs diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 29f76cfb8..bb5487f02 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -4,6 +4,7 @@ use super::*; mod insert; mod movement; +mod paste_all_selections; mod write; #[tokio::test(flavor = "multi_thread")] diff --git a/helix-term/tests/test/commands/paste_all_selections.rs b/helix-term/tests/test/commands/paste_all_selections.rs new file mode 100644 index 000000000..43458c87e --- /dev/null +++ b/helix-term/tests/test/commands/paste_all_selections.rs @@ -0,0 +1,59 @@ +use super::*; + +use helix_core::hashmap; +use helix_term::keymap; +use helix_view::document::Mode; + +#[tokio::test(flavor = "multi_thread")] +async fn paste_all_selections() -> anyhow::Result<()> { + let mut config = Config::default(); + config.keys.insert( + Mode::Normal, + keymap!({"Normal Mode" + "A-P" => paste_all_selections_before, + "A-p" => paste_all_selections_after, + }), + ); + + // Test paste_all_selections_before + // Selection direction matches paste target selections. + test_with_config( + AppBuilder::new().with_config(config.clone()), + ( + indoc! {"\ + #(|one)#_cat + #(|two)#_dog + #[|three]#_cow + "}, + "y", + indoc! {"\ + #(|one)##(|two)##(|three)#one_cat + #(|one)##(|two)##(|three)#two_dog + #(|one)##(|two)##[|three]#three_cow + "}, + ), + ) + .await?; + + // Test paste_all_selections_after + // Primary selection is last selection pasted for previous primary. + test_with_config( + AppBuilder::new().with_config(config.clone()), + ( + indoc! {"\ + #(one|)#_cat + #[two|]#_dog + #(three|)#_cow + "}, + "y", + indoc! {"\ + one#(one|)##(two|)##(three|)#_cat + two#(one|)##(two|)##[three|]#_dog + three#(one|)##(two|)##(three|)#_cow + "}, + ), + ) + .await?; + + Ok(()) +}