migrate test_with_config to use AppBuilder

pull/6385/head
Skyler Hawthorne 2 years ago committed by Michael Davis
parent d3b051d28e
commit 4bdeb9927b

@ -4,8 +4,8 @@ mod test {
use std::path::PathBuf; use std::path::PathBuf;
use helix_core::{syntax::AutoPairConfig, Position, Selection}; use helix_core::{syntax::AutoPairConfig, Selection};
use helix_term::{args::Args, config::Config}; use helix_term::config::Config;
use indoc::indoc; use indoc::indoc;

@ -3,12 +3,7 @@ use super::*;
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn auto_indent_c() -> anyhow::Result<()> { async fn auto_indent_c() -> anyhow::Result<()> {
test_with_config( test_with_config(
Args { AppBuilder::new().with_file("foo.c", None),
files: vec![(PathBuf::from("foo.c"), Position::default())],
..Default::default()
},
helpers::test_config(),
helpers::test_syntax_conf(None),
// switches to append mode? // switches to append mode?
( (
helpers::platform_line("void foo() {#[|}]#"), helpers::platform_line("void foo() {#[|}]#"),

@ -41,9 +41,7 @@ async fn insert_configured_multi_byte_chars() -> anyhow::Result<()> {
for (open, close) in pairs.iter() { for (open, close) in pairs.iter() {
test_with_config( test_with_config(
Args::default(), AppBuilder::new().with_config(config.clone()),
config.clone(),
helpers::test_syntax_conf(None),
( (
format!("#[{}|]#", LINE_END), format!("#[{}|]#", LINE_END),
format!("i{}", open), format!("i{}", open),
@ -53,9 +51,7 @@ async fn insert_configured_multi_byte_chars() -> anyhow::Result<()> {
.await?; .await?;
test_with_config( test_with_config(
Args::default(), AppBuilder::new().with_config(config.clone()),
config.clone(),
helpers::test_syntax_conf(None),
( (
format!("{}#[{}|]#{}", open, close, LINE_END), format!("{}#[{}|]#{}", open, close, LINE_END),
format!("i{}", close), format!("i{}", close),
@ -170,15 +166,13 @@ async fn insert_before_eol() -> anyhow::Result<()> {
async fn insert_auto_pairs_disabled() -> anyhow::Result<()> { async fn insert_auto_pairs_disabled() -> anyhow::Result<()> {
for pair in DEFAULT_PAIRS { for pair in DEFAULT_PAIRS {
test_with_config( test_with_config(
Args::default(), AppBuilder::new().with_config(Config {
Config {
editor: helix_view::editor::Config { editor: helix_view::editor::Config {
auto_pairs: AutoPairConfig::Enable(false), auto_pairs: AutoPairConfig::Enable(false),
..Default::default() ..Default::default()
}, },
..Default::default() ..Default::default()
}, }),
helpers::test_syntax_conf(None),
( (
format!("#[{}|]#", LINE_END), format!("#[{}|]#", LINE_END),
format!("i{}", pair.0), 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 /// document, selection, and sequence of key presses, and you just
/// want to verify the resulting document and selection. /// want to verify the resulting document and selection.
pub async fn test_with_config<T: Into<TestCase>>( pub async fn test_with_config<T: Into<TestCase>>(
args: Args, app_builder: AppBuilder,
mut config: Config,
syn_conf: helix_core::syntax::Configuration,
test_case: T, test_case: T,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let test_case = test_case.into(); let test_case = test_case.into();
config = helix_term::keymap::merge_keys(config); let app = app_builder.build()?;
let app = Application::new(args, config, syn_conf)?;
test_key_sequence_with_input_text( test_key_sequence_with_input_text(
Some(app), 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<()> { pub async fn test<T: Into<TestCase>>(test_case: T) -> anyhow::Result<()> {
test_with_config( test_with_config(AppBuilder::default(), test_case).await
Args::default(),
test_config(),
test_syntax_conf(None),
test_case,
)
.await
} }
pub fn temp_file_with_contents<S: AsRef<str>>( 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: // Remove this attribute once `with_config` is used in a test:
#[allow(dead_code)] #[allow(dead_code)]
pub fn with_config(mut self, config: Config) -> Self { pub fn with_config(mut self, config: Config) -> Self {
self.config = config; self.config = helix_term::keymap::merge_keys(config);
self self
} }

@ -413,12 +413,7 @@ async fn cursor_position_append_eof() -> anyhow::Result<()> {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> { async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> {
test_with_config( test_with_config(
Args { AppBuilder::new().with_file("foo.rs", None),
files: vec![(PathBuf::from("foo.rs"), Position::default())],
..Default::default()
},
Config::default(),
helpers::test_syntax_conf(None),
( (
helpers::platform_line(indoc! {"\ helpers::platform_line(indoc! {"\
#[/|]#// Increments #[/|]#// Increments
@ -443,12 +438,7 @@ async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn select_mode_tree_sitter_prev_function_unselects_object() -> anyhow::Result<()> { async fn select_mode_tree_sitter_prev_function_unselects_object() -> anyhow::Result<()> {
test_with_config( test_with_config(
Args { AppBuilder::new().with_file("foo.rs", None),
files: vec![(PathBuf::from("foo.rs"), Position::default())],
..Default::default()
},
Config::default(),
helpers::test_syntax_conf(None),
( (
helpers::platform_line(indoc! {"\ helpers::platform_line(indoc! {"\
/// Increments /// 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<()> { async fn select_mode_tree_sitter_prev_function_goes_backwards_to_object() -> anyhow::Result<()> {
// Note: the anchor stays put and the head moves back. // Note: the anchor stays put and the head moves back.
test_with_config( test_with_config(
Args { AppBuilder::new().with_file("foo.rs", None),
files: vec![(PathBuf::from("foo.rs"), Position::default())],
..Default::default()
},
Config::default(),
helpers::test_syntax_conf(None),
( (
helpers::platform_line(indoc! {"\ helpers::platform_line(indoc! {"\
/// Increments /// Increments
@ -503,12 +488,7 @@ async fn select_mode_tree_sitter_prev_function_goes_backwards_to_object() -> any
.await?; .await?;
test_with_config( test_with_config(
Args { AppBuilder::new().with_file("foo.rs", None),
files: vec![(PathBuf::from("foo.rs"), Position::default())],
..Default::default()
},
Config::default(),
helpers::test_syntax_conf(None),
( (
helpers::platform_line(indoc! {"\ helpers::platform_line(indoc! {"\
/// Increments /// Increments

Loading…
Cancel
Save