From 01af29ae271ec04bb8593eebd18a67835cb58bc5 Mon Sep 17 00:00:00 2001 From: woojiq Date: Tue, 1 Aug 2023 00:28:03 +0300 Subject: [PATCH] test(picker): basic functionality --- helix-term/tests/integration.rs | 4 +- helix-term/tests/test/picker.rs | 75 +++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 helix-term/tests/test/picker.rs diff --git a/helix-term/tests/integration.rs b/helix-term/tests/integration.rs index aa8b4a80aa2d..a62f006600a9 100644 --- a/helix-term/tests/integration.rs +++ b/helix-term/tests/integration.rs @@ -1,5 +1,4 @@ -// XXX remove before PR -// #[cfg(feature = "integration")] +#[cfg(feature = "integration")] mod test { mod helpers; @@ -20,6 +19,7 @@ mod test { mod auto_pairs; mod commands; mod movement; + mod picker; mod prompt; mod splits; } diff --git a/helix-term/tests/test/picker.rs b/helix-term/tests/test/picker.rs new file mode 100644 index 000000000000..874f813b7151 --- /dev/null +++ b/helix-term/tests/test/picker.rs @@ -0,0 +1,75 @@ +use std::fs; + +use helix_core::Range; +use helix_loader::{current_working_dir, set_current_working_dir}; +use helix_view::{current_ref, editor::Action}; +use tempfile::{Builder, TempDir}; + +use super::*; + +#[tokio::test(flavor = "multi_thread")] +async fn test_picker_alt_ret() -> anyhow::Result<()> { + // Create two files, open the first and run a global search for a word + // from the second file. Press to have helix open the second file in the + // new buffer, but not change focus. Then check whether the word is highlighted + // correctly and the view of the first file has not changed. + let tmp_dir = TempDir::new()?; + set_current_working_dir(tmp_dir.path().into())?; + + let mut app = AppBuilder::new().build()?; + + log::debug!( + "set current working directory to {:?}", + current_working_dir() + ); + + // Add prefix so helix doesn't hide these files in a picker + let files = [ + Builder::new().prefix("1").tempfile_in(&tmp_dir)?, + Builder::new().prefix("2").tempfile_in(&tmp_dir)?, + ]; + fs::write(files[0].path(), "1\n2\n3\n4")?; + fs::write(files[1].path(), "first\nsecond")?; + + log::debug!( + "created and writed two temporary files: {:?} & {:?}", + files[0].path(), + files[1].path() + ); + + // Manually open to save the offset, otherwise we won't be able to change the state in the Fn trait + app.editor.open(files[0].path(), Action::Replace)?; + let view_offset = current_ref!(app.editor).0.offset; + + test_key_sequences( + &mut app, + vec![ + (Some("/"), None), + (Some("second"), None), + ( + Some(""), + Some(&|app| { + let (view, doc) = current_ref!(app.editor); + assert_eq!(doc.path().unwrap(), files[0].path()); + let select_ranges = doc.selection(view.id).ranges(); + assert_eq!(select_ranges[0], Range::new(0, 1)); + assert_eq!(view.offset, view_offset); + }), + ), + ( + Some(":buffernext"), + Some(&|app| { + let (view, doc) = current_ref!(app.editor); + assert_eq!(doc.path().unwrap(), files[1].path()); + let select_ranges = doc.selection(view.id).ranges(); + assert_eq!(select_ranges.len(), 1); + assert_eq!(select_ranges[0], Range::new(6, 12)); + }), + ), + ], + false, + ) + .await?; + + Ok(()) +}