on master help sign in
migrate test_with_config to use AppBuilder
commit4bdeb9927b5aa0fb71484faae8f3aa9c5ce67381 authorSkyler Hawthorne <skyler@dead10ck.com> dateThu 10 Nov 2022, 23:58 (4 years ago) parentd3b051d
5 files changed+15−55
helix-term/tests/integration.rs+2−2 helix-term/tests/test/auto_indent.rs+1−6 helix-term/tests/test/auto_pairs.rs+4−10 helix-term/tests/test/helpers.rs+4−13 helix-term/tests/test/movement.rs+4−24
helix-term/tests/integration.rs+2−2
@@ -4,8 +4,8 @@ mod test {
44
55 use std::path::PathBuf;
66
7− use helix_core::{syntax::AutoPairConfig, Position, Selection};
8− use helix_term::{args::Args, config::Config};
7+ use helix_core::{syntax::AutoPairConfig, Selection};
8+ use helix_term::config::Config;
99
1010 use indoc::indoc;
1111
helix-term/tests/test/auto_indent.rs+1−6
@@ -3,12 +3,7 @@ use super::*;
33#[tokio::test(flavor = "multi_thread")]
44async fn auto_indent_c() -> anyhow::Result<()> {
55 test_with_config(
6− Args {
7− files: vec![(PathBuf::from("foo.c"), Position::default())],
8− ..Default::default()
9− },
10− helpers::test_config(),
11− helpers::test_syntax_conf(None),
6+ AppBuilder::new().with_file("foo.c", None),
127 // switches to append mode?
138 (
149 helpers::platform_line("void foo() {#[|}]#"),
helix-term/tests/test/auto_pairs.rs+4−10
@@ -41,9 +41,7 @@ async fn insert_configured_multi_byte_chars() -> anyhow::Result<()> {
4141
4242 for (open, close) in pairs.iter() {
4343 test_with_config(
44− Args::default(),
45− config.clone(),
46− helpers::test_syntax_conf(None),
44+ AppBuilder::new().with_config(config.clone()),
4745 (
4846 format!("#[{}|]#", LINE_END),
4947 format!("i{}", open),
@@ -53,9 +51,7 @@ async fn insert_configured_multi_byte_chars() -> anyhow::Result<()> {
5351 .await?;
5452
5553 test_with_config(
56− Args::default(),
57− config.clone(),
58− helpers::test_syntax_conf(None),
54+ AppBuilder::new().with_config(config.clone()),
5955 (
6056 format!("{}#[{}|]#{}", open, close, LINE_END),
6157 format!("i{}", close),
@@ -170,15 +166,13 @@ async fn insert_before_eol() -> anyhow::Result<()> {
170166async fn insert_auto_pairs_disabled() -> anyhow::Result<()> {
171167 for pair in DEFAULT_PAIRS {
172168 test_with_config(
173− Args::default(),
174− Config {
169+ AppBuilder::new().with_config(Config {
175170 editor: helix_view::editor::Config {
176171 auto_pairs: AutoPairConfig::Enable(false),
177172 ..Default::default()
178173 },
179174 ..Default::default()
180− },
181− helpers::test_syntax_conf(None),
175+ }),
182176 (
183177 format!("#[{}|]#", LINE_END),
184178 format!("i{}", pair.0),
helix-term/tests/test/helpers.rs+4−13
@@ -178,14 +178,11 @@ pub fn test_syntax_conf(overrides: Option<String>) -> helix_core::syntax::Config
178178/// document, selection, and sequence of key presses, and you just
179179/// want to verify the resulting document and selection.
180180pub async fn test_with_config<T: Into<TestCase>>(
181− args: Args,
182− mut config: Config,
183− syn_conf: helix_core::syntax::Configuration,
181+ app_builder: AppBuilder,
184182 test_case: T,
185183) -> anyhow::Result<()> {
186184 let test_case = test_case.into();
187− config = helix_term::keymap::merge_keys(config);
188− let app = Application::new(args, config, syn_conf)?;
185+ let app = app_builder.build()?;
189186
190187 test_key_sequence_with_input_text(
191188 Some(app),
@@ -206,13 +203,7 @@ pub async fn test_with_config<T: Into<TestCase>>(
206203}
207204
208205pub async fn test<T: Into<TestCase>>(test_case: T) -> anyhow::Result<()> {
209− test_with_config(
210− Args::default(),
211− test_config(),
212− test_syntax_conf(None),
213− test_case,
214− )
215− .await
206+ test_with_config(AppBuilder::default(), test_case).await
216207}
217208
218209pub fn temp_file_with_contents<S: AsRef<str>>(
@@ -310,7 +301,7 @@ impl AppBuilder {
310301 // Remove this attribute once `with_config` is used in a test:
311302 #[allow(dead_code)]
312303 pub fn with_config(mut self, config: Config) -> Self {
313− self.config = config;
304+ self.config = helix_term::keymap::merge_keys(config);
314305 self
315306 }
316307
helix-term/tests/test/movement.rs+4−24
@@ -413,12 +413,7 @@ async fn cursor_position_append_eof() -> anyhow::Result<()> {
413413#[tokio::test(flavor = "multi_thread")]
414414async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> {
415415 test_with_config(
416− Args {
417− files: vec![(PathBuf::from("foo.rs"), Position::default())],
418− ..Default::default()
419− },
420− Config::default(),
421− helpers::test_syntax_conf(None),
416+ AppBuilder::new().with_file("foo.rs", None),
422417 (
423418 helpers::platform_line(indoc! {"\
424419 #[/|]#// Increments
@@ -443,12 +438,7 @@ async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::
443438#[tokio::test(flavor = "multi_thread")]
444439async fn select_mode_tree_sitter_prev_function_unselects_object() -> anyhow::Result<()> {
445440 test_with_config(
446− Args {
447− files: vec![(PathBuf::from("foo.rs"), Position::default())],
448− ..Default::default()
449− },
450− Config::default(),
451− helpers::test_syntax_conf(None),
441+ AppBuilder::new().with_file("foo.rs", None),
452442 (
453443 helpers::platform_line(indoc! {"\
454444 /// Increments
@@ -474,12 +464,7 @@ async fn select_mode_tree_sitter_prev_function_unselects_object() -> anyhow::Res
474464async fn select_mode_tree_sitter_prev_function_goes_backwards_to_object() -> anyhow::Result<()> {
475465 // Note: the anchor stays put and the head moves back.
476466 test_with_config(
477− Args {
478− files: vec![(PathBuf::from("foo.rs"), Position::default())],
479− ..Default::default()
480− },
481− Config::default(),
482− helpers::test_syntax_conf(None),
467+ AppBuilder::new().with_file("foo.rs", None),
483468 (
484469 helpers::platform_line(indoc! {"\
485470 /// Increments
@@ -503,12 +488,7 @@ async fn select_mode_tree_sitter_prev_function_goes_backwards_to_object() -> any
503488 .await?;
504489
505490 test_with_config(
506− Args {
507− files: vec![(PathBuf::from("foo.rs"), Position::default())],
508− ..Default::default()
509− },
510− Config::default(),
511− helpers::test_syntax_conf(None),
491+ AppBuilder::new().with_file("foo.rs", None),
512492 (
513493 helpers::platform_line(indoc! {"\
514494 /// Increments