1
0
mirror of https://github.com/helix-editor/helix synced 2024-11-10 10:34:45 +01:00

migrate test_with_config to use AppBuilder

This commit is contained in:
Skyler Hawthorne 2022-11-10 23:58:03 -05:00 committed by Michael Davis
parent d3b051d28e
commit 4bdeb9927b
5 changed files with 15 additions and 55 deletions

@ -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;

@ -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() {#[|}]#"),

@ -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),

@ -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),
@ -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>>(
@ -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
}

@ -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