Skip to content

Commit

Permalink
migrate test_with_config to use AppBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
dead10ck committed Mar 2, 2023
1 parent e5b373e commit ec3ff23
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 55 deletions.
4 changes: 2 additions & 2 deletions helix-term/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 1 addition & 6 deletions helix-term/tests/test/auto_indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {#[|}]#"),
Expand Down
14 changes: 4 additions & 10 deletions helix-term/tests/test/auto_pairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
17 changes: 4 additions & 13 deletions helix-term/tests/test/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,11 @@ pub fn test_syntax_conf(overrides: Option<String>) -> 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<T: Into<TestCase>>(
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),
Expand All @@ -206,13 +203,7 @@ pub async fn test_with_config<T: Into<TestCase>>(
}

pub async fn test<T: Into<TestCase>>(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<S: AsRef<str>>(
Expand Down Expand Up @@ -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
}

Expand Down
28 changes: 4 additions & 24 deletions helix-term/tests/test/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ec3ff23

Please sign in to comment.