on master help sign in
migrate test_with_config to use AppBuilder
4bdeb99Skyler Hawthorne
helix-term/tests/integration.rs+2−2
@@ -4,8 +4,8 @@ mod test {
4
4
5 use std::path::PathBuf;
5 use std::path::PathBuf;
6
6
7− use helix_core::{syntax::AutoPairConfig, Position, Selection};
7+ use helix_core::{syntax::AutoPairConfig, Selection};
8− use helix_term::{args::Args, config::Config};
8+ use helix_term::config::Config;
9
9
10 use indoc::indoc;
10 use indoc::indoc;
11
11
helix-term/tests/test/auto_indent.rs+1−6
@@ -3,12 +3,7 @@ use super::*;
3#[tokio::test(flavor = "multi_thread")]
3#[tokio::test(flavor = "multi_thread")]
4async fn auto_indent_c() -> anyhow::Result<()> {
4async fn auto_indent_c() -> anyhow::Result<()> {
5 test_with_config(
5 test_with_config(
6− Args {
6+ AppBuilder::new().with_file("foo.c", None),
7− files: vec![(PathBuf::from("foo.c"), Position::default())],
8− ..Default::default()
9− },
10− helpers::test_config(),
11− helpers::test_syntax_conf(None),
12 // switches to append mode?
7 // switches to append mode?
13 (
8 (
14 helpers::platform_line("void foo() {#[|}]#"),
9 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<()> {
41
41
42 for (open, close) in pairs.iter() {
42 for (open, close) in pairs.iter() {
43 test_with_config(
43 test_with_config(
44− Args::default(),
45− config.clone(),
44+ AppBuilder::new().with_config(config.clone()),
46− helpers::test_syntax_conf(None),
47 (
45 (
48 format!("#[{}|]#", LINE_END),
46 format!("#[{}|]#", LINE_END),
49 format!("i{}", open),
47 format!("i{}", open),
@@ -53,9 +51,7 @@ async fn insert_configured_multi_byte_chars() -> anyhow::Result<()> {
53 .await?;
51 .await?;
54
52
55 test_with_config(
53 test_with_config(
56− Args::default(),
57− config.clone(),
54+ AppBuilder::new().with_config(config.clone()),
58− helpers::test_syntax_conf(None),
59 (
55 (
60 format!("{}#[{}|]#{}", open, close, LINE_END),
56 format!("{}#[{}|]#{}", open, close, LINE_END),
61 format!("i{}", close),
57 format!("i{}", close),
@@ -170,15 +166,13 @@ async fn insert_before_eol() -> anyhow::Result<()> {
170async fn insert_auto_pairs_disabled() -> anyhow::Result<()> {
166async fn insert_auto_pairs_disabled() -> anyhow::Result<()> {
171 for pair in DEFAULT_PAIRS {
167 for pair in DEFAULT_PAIRS {
172 test_with_config(
168 test_with_config(
173− Args::default(),
169+ AppBuilder::new().with_config(Config {
174− Config {
175 editor: helix_view::editor::Config {
170 editor: helix_view::editor::Config {
176 auto_pairs: AutoPairConfig::Enable(false),
171 auto_pairs: AutoPairConfig::Enable(false),
177 ..Default::default()
172 ..Default::default()
178 },
173 },
179 ..Default::default()
174 ..Default::default()
180− },
175+ }),
181− helpers::test_syntax_conf(None),
182 (
176 (
183 format!("#[{}|]#", LINE_END),
177 format!("#[{}|]#", LINE_END),
184 format!("i{}", pair.0),
178 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
178/// document, selection, and sequence of key presses, and you just
178/// document, selection, and sequence of key presses, and you just
179/// want to verify the resulting document and selection.
179/// want to verify the resulting document and selection.
180pub async fn test_with_config<T: Into<TestCase>>(
180pub async fn test_with_config<T: Into<TestCase>>(
181− args: Args,
181+ app_builder: AppBuilder,
182− mut config: Config,
183− syn_conf: helix_core::syntax::Configuration,
184 test_case: T,
182 test_case: T,
185) -> anyhow::Result<()> {
183) -> anyhow::Result<()> {
186 let test_case = test_case.into();
184 let test_case = test_case.into();
187− config = helix_term::keymap::merge_keys(config);
185+ let app = app_builder.build()?;
188− let app = Application::new(args, config, syn_conf)?;
189
186
190 test_key_sequence_with_input_text(
187 test_key_sequence_with_input_text(
191 Some(app),
188 Some(app),
@@ -206,13 +203,7 @@ pub async fn test_with_config<T: Into<TestCase>>(
206}
203}
207
204
208pub async fn test<T: Into<TestCase>>(test_case: T) -> anyhow::Result<()> {
205pub async fn test<T: Into<TestCase>>(test_case: T) -> anyhow::Result<()> {
209− test_with_config(
206+ test_with_config(AppBuilder::default(), test_case).await
210− Args::default(),
211− test_config(),
212− test_syntax_conf(None),
213− test_case,
214− )
215− .await
216}
207}
217
208
218pub fn temp_file_with_contents<S: AsRef<str>>(
209pub fn temp_file_with_contents<S: AsRef<str>>(
@@ -310,7 +301,7 @@ impl AppBuilder {
310 // Remove this attribute once `with_config` is used in a test:
301 // Remove this attribute once `with_config` is used in a test:
311 #[allow(dead_code)]
302 #[allow(dead_code)]
312 pub fn with_config(mut self, config: Config) -> Self {
303 pub fn with_config(mut self, config: Config) -> Self {
313− self.config = config;
304+ self.config = helix_term::keymap::merge_keys(config);
314 self
305 self
315 }
306 }
316
307
helix-term/tests/test/movement.rs+4−24
@@ -413,12 +413,7 @@ async fn cursor_position_append_eof() -> anyhow::Result<()> {
413#[tokio::test(flavor = "multi_thread")]
413#[tokio::test(flavor = "multi_thread")]
414async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> {
414async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> {
415 test_with_config(
415 test_with_config(
416− Args {
416+ AppBuilder::new().with_file("foo.rs", None),
417− files: vec![(PathBuf::from("foo.rs"), Position::default())],
418− ..Default::default()
419− },
420− Config::default(),
421− helpers::test_syntax_conf(None),
422 (
417 (
423 helpers::platform_line(indoc! {"\
418 helpers::platform_line(indoc! {"\
424 #[/|]#// Increments
419 #[/|]#// Increments
@@ -443,12 +438,7 @@ async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::
443#[tokio::test(flavor = "multi_thread")]
438#[tokio::test(flavor = "multi_thread")]
444async fn select_mode_tree_sitter_prev_function_unselects_object() -> anyhow::Result<()> {
439async fn select_mode_tree_sitter_prev_function_unselects_object() -> anyhow::Result<()> {
445 test_with_config(
440 test_with_config(
446− Args {
441+ AppBuilder::new().with_file("foo.rs", None),
447− files: vec![(PathBuf::from("foo.rs"), Position::default())],
448− ..Default::default()
449− },
450− Config::default(),
451− helpers::test_syntax_conf(None),
452 (
442 (
453 helpers::platform_line(indoc! {"\
443 helpers::platform_line(indoc! {"\
454 /// Increments
444 /// Increments
@@ -474,12 +464,7 @@ async fn select_mode_tree_sitter_prev_function_unselects_object() -> anyhow::Res
474async fn select_mode_tree_sitter_prev_function_goes_backwards_to_object() -> anyhow::Result<()> {
464async fn select_mode_tree_sitter_prev_function_goes_backwards_to_object() -> anyhow::Result<()> {
475 // Note: the anchor stays put and the head moves back.
465 // Note: the anchor stays put and the head moves back.
476 test_with_config(
466 test_with_config(
477− Args {
467+ AppBuilder::new().with_file("foo.rs", None),
478− files: vec![(PathBuf::from("foo.rs"), Position::default())],
479− ..Default::default()
480− },
481− Config::default(),
482− helpers::test_syntax_conf(None),
483 (
468 (
484 helpers::platform_line(indoc! {"\
469 helpers::platform_line(indoc! {"\
485 /// Increments
470 /// Increments
@@ -503,12 +488,7 @@ async fn select_mode_tree_sitter_prev_function_goes_backwards_to_object() -> any
503 .await?;
488 .await?;
504
489
505 test_with_config(
490 test_with_config(
506− Args {
491+ AppBuilder::new().with_file("foo.rs", None),
507− files: vec![(PathBuf::from("foo.rs"), Position::default())],
508− ..Default::default()
509− },
510− Config::default(),
511− helpers::test_syntax_conf(None),
512 (
492 (
513 helpers::platform_line(indoc! {"\
493 helpers::platform_line(indoc! {"\
514 /// Increments
494 /// Increments