From 9c77e34b54737e3296349c632fad22761c30e322 Mon Sep 17 00:00:00 2001 From: Skyler Hawthorne Date: Thu, 10 Nov 2022 23:58:03 -0500 Subject: [PATCH] migrate test_with_config to use AppBuilder --- helix-term/tests/integration.rs | 4 ++-- helix-term/tests/test/auto_indent.rs | 7 +------ helix-term/tests/test/auto_pairs.rs | 14 ++++---------- helix-term/tests/test/helpers.rs | 17 ++++------------- helix-term/tests/test/movement.rs | 28 ++++------------------------ 5 files changed, 15 insertions(+), 55 deletions(-) diff --git a/helix-term/tests/integration.rs b/helix-term/tests/integration.rs index be1bfc2c0efb7..cec374afa4921 100644 --- a/helix-term/tests/integration.rs +++ b/helix-term/tests/integration.rs @@ -4,8 +4,8 @@ mod test { use std::path::PathBuf; - use helix_core::{syntax::AutoPairConfig, Position, Selection}; - use helix_term::{args::Args, config::Config}; + use helix_core::{syntax::AutoPairConfig, Selection}; + use helix_term::config::Config; use indoc::indoc; diff --git a/helix-term/tests/test/auto_indent.rs b/helix-term/tests/test/auto_indent.rs index e626acad31793..5132d44d983b4 100644 --- a/helix-term/tests/test/auto_indent.rs +++ b/helix-term/tests/test/auto_indent.rs @@ -3,12 +3,7 @@ use super::*; #[tokio::test(flavor = "multi_thread")] async fn auto_indent_c() -> anyhow::Result<()> { test_with_config( - Args { - files: vec![(PathBuf::from("foo.c"), Position::default())], - ..Default::default() - }, - helpers::test_config(), - helpers::test_syntax_conf(None), + AppBuilder::new().with_file("foo.c", None), // switches to append mode? ( helpers::platform_line("void foo() {#[|}]#"), diff --git a/helix-term/tests/test/auto_pairs.rs b/helix-term/tests/test/auto_pairs.rs index e18c71195fb49..e10e0840bcb86 100644 --- a/helix-term/tests/test/auto_pairs.rs +++ b/helix-term/tests/test/auto_pairs.rs @@ -41,9 +41,7 @@ async fn insert_configured_multi_byte_chars() -> anyhow::Result<()> { for (open, close) in pairs.iter() { test_with_config( - Args::default(), - config.clone(), - helpers::test_syntax_conf(None), + AppBuilder::new().with_config(config.clone()), ( format!("#[{}|]#", LINE_END), format!("i{}", open), @@ -53,9 +51,7 @@ async fn insert_configured_multi_byte_chars() -> anyhow::Result<()> { .await?; test_with_config( - Args::default(), - config.clone(), - helpers::test_syntax_conf(None), + AppBuilder::new().with_config(config.clone()), ( format!("{}#[{}|]#{}", open, close, LINE_END), format!("i{}", close), @@ -170,15 +166,13 @@ async fn insert_before_eol() -> anyhow::Result<()> { async fn insert_auto_pairs_disabled() -> anyhow::Result<()> { for pair in DEFAULT_PAIRS { test_with_config( - Args::default(), - Config { + AppBuilder::new().with_config(Config { editor: helix_view::editor::Config { auto_pairs: AutoPairConfig::Enable(false), ..Default::default() }, ..Default::default() - }, - helpers::test_syntax_conf(None), + }), ( format!("#[{}|]#", LINE_END), format!("i{}", pair.0), diff --git a/helix-term/tests/test/helpers.rs b/helix-term/tests/test/helpers.rs index 77332fa581bbd..ccd07bfa54c18 100644 --- a/helix-term/tests/test/helpers.rs +++ b/helix-term/tests/test/helpers.rs @@ -178,14 +178,11 @@ pub fn test_syntax_conf(overrides: Option) -> helix_core::syntax::Config /// document, selection, and sequence of key presses, and you just /// want to verify the resulting document and selection. pub async fn test_with_config>( - args: Args, - mut config: Config, - syn_conf: helix_core::syntax::Configuration, + app_builder: AppBuilder, test_case: T, ) -> anyhow::Result<()> { let test_case = test_case.into(); - config = helix_term::keymap::merge_keys(config); - let app = Application::new(args, config, syn_conf)?; + let app = app_builder.build()?; test_key_sequence_with_input_text( Some(app), @@ -206,13 +203,7 @@ pub async fn test_with_config>( } pub async fn test>(test_case: T) -> anyhow::Result<()> { - test_with_config( - Args::default(), - test_config(), - test_syntax_conf(None), - test_case, - ) - .await + test_with_config(AppBuilder::default(), test_case).await } pub fn temp_file_with_contents>( @@ -310,7 +301,7 @@ impl AppBuilder { // Remove this attribute once `with_config` is used in a test: #[allow(dead_code)] pub fn with_config(mut self, config: Config) -> Self { - self.config = config; + self.config = helix_term::keymap::merge_keys(config); self } diff --git a/helix-term/tests/test/movement.rs b/helix-term/tests/test/movement.rs index 6cc89021d0465..e10ec6f5db3bf 100644 --- a/helix-term/tests/test/movement.rs +++ b/helix-term/tests/test/movement.rs @@ -413,12 +413,7 @@ async fn cursor_position_append_eof() -> anyhow::Result<()> { #[tokio::test(flavor = "multi_thread")] async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> { test_with_config( - Args { - files: vec![(PathBuf::from("foo.rs"), Position::default())], - ..Default::default() - }, - Config::default(), - helpers::test_syntax_conf(None), + AppBuilder::new().with_file("foo.rs", None), ( helpers::platform_line(indoc! {"\ #[/|]#// Increments @@ -443,12 +438,7 @@ async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow:: #[tokio::test(flavor = "multi_thread")] async fn select_mode_tree_sitter_prev_function_unselects_object() -> anyhow::Result<()> { test_with_config( - Args { - files: vec![(PathBuf::from("foo.rs"), Position::default())], - ..Default::default() - }, - Config::default(), - helpers::test_syntax_conf(None), + AppBuilder::new().with_file("foo.rs", None), ( helpers::platform_line(indoc! {"\ /// Increments @@ -474,12 +464,7 @@ async fn select_mode_tree_sitter_prev_function_unselects_object() -> anyhow::Res async fn select_mode_tree_sitter_prev_function_goes_backwards_to_object() -> anyhow::Result<()> { // Note: the anchor stays put and the head moves back. test_with_config( - Args { - files: vec![(PathBuf::from("foo.rs"), Position::default())], - ..Default::default() - }, - Config::default(), - helpers::test_syntax_conf(None), + AppBuilder::new().with_file("foo.rs", None), ( helpers::platform_line(indoc! {"\ /// Increments @@ -503,12 +488,7 @@ async fn select_mode_tree_sitter_prev_function_goes_backwards_to_object() -> any .await?; test_with_config( - Args { - files: vec![(PathBuf::from("foo.rs"), Position::default())], - ..Default::default() - }, - Config::default(), - helpers::test_syntax_conf(None), + AppBuilder::new().with_file("foo.rs", None), ( helpers::platform_line(indoc! {"\ /// Increments