diff --git a/src/application.rs b/src/application.rs index 7791b7d0c..cd538c9c0 100644 --- a/src/application.rs +++ b/src/application.rs @@ -221,7 +221,6 @@ mod tests { test_helpers::{ DefaultTestModule, TestModuleProvider, - create_config, create_event_reader, mocks, with_git_directory, @@ -289,7 +288,7 @@ mod tests { #[test] fn todo_file_options_without_command() { - let mut config = create_config(); + let mut config = Config::default(); config.undo_limit = 10; config.git.comment_char = String::from("#"); config.post_modified_line_exec_command = None; @@ -303,7 +302,7 @@ mod tests { #[test] fn todo_file_options_with_command() { - let mut config = create_config(); + let mut config = Config::default(); config.undo_limit = 10; config.git.comment_char = String::from("#"); config.post_modified_line_exec_command = Some(String::from("command")); diff --git a/src/components/confirm/tests.rs b/src/components/confirm/tests.rs index d197d8041..a9f221813 100644 --- a/src/components/confirm/tests.rs +++ b/src/components/confirm/tests.rs @@ -4,7 +4,7 @@ use super::*; use crate::{ assert_rendered_output, input::StandardEvent, - test_helpers::{assertions::assert_rendered_output::AssertRenderOptions, create_test_keybindings}, + test_helpers::assertions::assert_rendered_output::AssertRenderOptions, }; #[test] @@ -23,7 +23,7 @@ fn render() { #[test] fn read_event_yes_uppercase() { assert_eq!( - Confirm::read_event(Event::from('Y'), &create_test_keybindings()), + Confirm::read_event(Event::from('Y'), &KeyBindings::default()), Event::from(StandardEvent::Yes) ); } @@ -31,7 +31,7 @@ fn read_event_yes_uppercase() { #[test] fn read_event_yes_lowercase() { assert_eq!( - Confirm::read_event(Event::from('y'), &create_test_keybindings()), + Confirm::read_event(Event::from('y'), &KeyBindings::default()), Event::from(StandardEvent::Yes) ); } @@ -39,7 +39,7 @@ fn read_event_yes_lowercase() { #[test] fn read_event_no_lowercase() { assert_eq!( - Confirm::read_event(Event::from('n'), &create_test_keybindings()), + Confirm::read_event(Event::from('n'), &KeyBindings::default()), Event::from(StandardEvent::No) ); } @@ -47,7 +47,7 @@ fn read_event_no_lowercase() { #[test] fn read_event_no_uppercase() { assert_eq!( - Confirm::read_event(Event::from('N'), &create_test_keybindings()), + Confirm::read_event(Event::from('N'), &KeyBindings::default()), Event::from(StandardEvent::No) ); } @@ -55,7 +55,7 @@ fn read_event_no_uppercase() { #[test] fn read_event_not_key_event() { assert_eq!( - Confirm::read_event(Event::None, &create_test_keybindings()), + Confirm::read_event(Event::None, &KeyBindings::default()), Event::None ); } @@ -63,7 +63,7 @@ fn read_event_not_key_event() { #[test] fn read_event_not_char_event() { assert_eq!( - Confirm::read_event(Event::from(KeyCode::Backspace), &create_test_keybindings()), + Confirm::read_event(Event::from(KeyCode::Backspace), &KeyBindings::default()), Event::from(KeyCode::Backspace) ); } diff --git a/src/config.rs b/src/config.rs index 327485f90..095b27bc3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -66,7 +66,7 @@ pub(crate) struct Config { } impl Config { - pub(crate) fn new_with_config(git_config: Option<&crate::git::Config>) -> Result { + pub(crate) fn new_with_config(git_config: &crate::git::Config) -> Result { Ok(Self { auto_select_next: get_bool(git_config, "interactive-rebase-tool.autoSelectNext", false)?, diff_ignore_whitespace: get_diff_ignore_whitespace( @@ -94,6 +94,25 @@ impl Config { } } +impl Default for Config { + fn default() -> Self { + Self { + auto_select_next: false, + diff_ignore_whitespace: DiffIgnoreWhitespaceSetting::None, + diff_ignore_blank_lines: false, + diff_show_whitespace: DiffShowWhitespaceSetting::Both, + diff_space_symbol: DEFAULT_SPACE_SYMBOL.to_owned(), + diff_tab_symbol: DEFAULT_TAB_SYMBOL.to_owned(), + diff_tab_width: 4, + undo_limit: 5000, + post_modified_line_exec_command: None, + git: GitConfig::default(), + key_bindings: KeyBindings::default(), + theme: Theme::default(), + } + } +} + impl TryFrom<&ConfigLoader> for Config { type Error = ConfigError; @@ -106,7 +125,7 @@ impl TryFrom<&ConfigLoader> for Config { let config = config_loader .load_config() .map_err(|e| ConfigError::new_read_error("", ConfigErrorCause::GitError(e)))?; - Self::new_with_config(Some(&config)) + Self::new_with_config(&config) } } @@ -114,7 +133,7 @@ impl TryFrom<&crate::git::Config> for Config { type Error = ConfigError; fn try_from(config: &crate::git::Config) -> Result { - Self::new_with_config(Some(config)) + Self::new_with_config(config) } } @@ -331,7 +350,7 @@ mod tests { vec!["[interactive-rebase-tool]", value.as_str()] }; with_git_config(&lines, |config| { - let config = Config::new_with_config(Some(&config)).unwrap(); + let config = Config::new_with_config(&config).unwrap(); assert_eq!(access(config), expected); }); } @@ -353,7 +372,7 @@ mod tests { ], |git_config| { assert_err_eq!( - Config::new_with_config(Some(&git_config)), + Config::new_with_config(&git_config), ConfigError::new( format!("interactive-rebase-tool.{config_name}").as_str(), config_value, @@ -378,7 +397,7 @@ mod tests { ], |git_config| { assert_err_eq!( - Config::new_with_config(Some(&git_config)), + Config::new_with_config(&git_config), ConfigError::new_read_error( format!("interactive-rebase-tool.{config_name}").as_str(), ConfigErrorCause::InvalidUtf diff --git a/src/config/diff_ignore_whitespace_setting.rs b/src/config/diff_ignore_whitespace_setting.rs index b53eba72b..101e40a42 100644 --- a/src/config/diff_ignore_whitespace_setting.rs +++ b/src/config/diff_ignore_whitespace_setting.rs @@ -13,3 +13,14 @@ pub(crate) enum DiffIgnoreWhitespaceSetting { /// ) flag. Change, } + +impl DiffIgnoreWhitespaceSetting { + pub(crate) fn parse(s: &str) -> Option { + match s.to_lowercase().as_str() { + "true" | "on" | "all" => Some(DiffIgnoreWhitespaceSetting::All), + "change" => Some(DiffIgnoreWhitespaceSetting::Change), + "false" | "off" | "none" => Some(DiffIgnoreWhitespaceSetting::None), + _ => None, + } + } +} diff --git a/src/config/diff_show_whitespace_setting.rs b/src/config/diff_show_whitespace_setting.rs index 5c9791b3c..ac7b90e19 100644 --- a/src/config/diff_show_whitespace_setting.rs +++ b/src/config/diff_show_whitespace_setting.rs @@ -11,3 +11,15 @@ pub(crate) enum DiffShowWhitespaceSetting { /// Show both leading and trailing whitespace characters. Both, } + +impl DiffShowWhitespaceSetting { + pub(crate) fn parse(s: &str) -> Option { + match s.to_lowercase().as_str() { + "true" | "on" | "both" => Some(DiffShowWhitespaceSetting::Both), + "trailing" => Some(DiffShowWhitespaceSetting::Trailing), + "leading" => Some(DiffShowWhitespaceSetting::Leading), + "false" | "off" | "none" => Some(DiffShowWhitespaceSetting::None), + _ => None, + } + } +} \ No newline at end of file diff --git a/src/config/git_config.rs b/src/config/git_config.rs index c398db6a7..aa34ac5f8 100644 --- a/src/config/git_config.rs +++ b/src/config/git_config.rs @@ -3,22 +3,33 @@ use std::env; use crate::{ config::{ ConfigError, - utils::{get_string, get_unsigned_integer, git_diff_renames}, + utils::{get_optional_string, get_unsigned_integer, git_diff_renames}, }, git::Config, }; -fn get_default_editor(git_config: Option<&Config>) -> Result { - env::var("GIT_EDITOR").or_else(|_| { - get_string( - git_config, - "core.editor", - (env::var("VISUAL") - .or_else(|_| env::var("EDITOR")) - .unwrap_or_else(|_| String::from("vi"))) - .as_str(), - ) - }) +fn get_default_editor() -> String { + ["GIT_EDITOR", "VISUAL", "EDITOR"] + .into_iter() + .find_map(|var| env::var(var).ok()) + .unwrap_or_else(|| String::from("vi")) +} + +/// XXX: this logic is duplicated in [`get_default_editor`] +fn get_default_editor_with_config(git_config: &Config) -> Result { + let editor = if let Ok(editor) = env::var("GIT_EDITOR") { + editor + } else if let Some(editor) = get_optional_string(git_config, "core.editor")? { + editor + } else if let Ok(editor) = env::var("VISUAL") { + editor + } else if let Ok(editor) = env::var("EDITOR") { + editor + } else { + String::from("vi") + }; + + Ok(editor) } /// Represents the git configuration options. @@ -56,11 +67,13 @@ pub(crate) struct GitConfig { } impl GitConfig { - pub(super) fn new_with_config(git_config: Option<&Config>) -> Result { - let mut comment_char = get_string(git_config, "core.commentChar", "#")?; - if comment_char.as_str().eq("auto") { - comment_char = String::from("#"); - } + pub(super) fn new_with_config(git_config: &Config) -> Result { + let comment_char = match get_optional_string(git_config, "core.commentChar") { + Ok(None) => "#".to_owned(), + Ok(Some(s)) if s == "auto" => "#".to_owned(), + Ok(Some(s)) => s, + Err(e) => return Err(e), + }; let (diff_renames, diff_copies) = git_diff_renames(git_config, "diff.renames")?; @@ -71,7 +84,7 @@ impl GitConfig { diff_rename_limit: get_unsigned_integer(git_config, "diff.renameLimit", 200)?, diff_renames, diff_copies, - editor: get_default_editor(git_config)?, + editor: get_default_editor_with_config(git_config)?, }) } } @@ -80,7 +93,21 @@ impl TryFrom<&Config> for GitConfig { type Error = ConfigError; fn try_from(config: &Config) -> Result { - Self::new_with_config(Some(config)) + Self::new_with_config(config) + } +} + +impl Default for GitConfig { + fn default() -> Self { + Self { + comment_char: "#".to_owned(), + diff_context: 3, + diff_interhunk_lines: 0, + diff_rename_limit: 200, + diff_renames: true, + diff_copies: false, + editor: get_default_editor(), + } } } @@ -103,7 +130,7 @@ mod tests { default $default:literal, $($value: literal => $expected: literal),* ) => { - let config = GitConfig::new_with_config(None).unwrap(); + let config = GitConfig::default(); let value = config.$key; assert_eq!( value, @@ -118,7 +145,7 @@ mod tests { let config_parent = format!("[{}]", $config_parent); let config_value = format!("{} = \"{value}\"", $config_name); with_git_config(&[config_parent.as_str(), config_value.as_str()], |git_config| { - let config = GitConfig::new_with_config(Some(&git_config)).unwrap(); + let config = GitConfig::new_with_config(&git_config).unwrap(); assert_eq!( config.$key, expected, @@ -166,7 +193,7 @@ mod tests { EnvVarAction::Remove("EDITOR"), ], || { - let config = GitConfig::new_with_config(None).unwrap(); + let config = GitConfig::default(); assert_eq!(config.editor, "vi"); }, ); @@ -181,7 +208,7 @@ mod tests { EnvVarAction::Set("GIT_EDITOR", String::from("git-editor")), ], || { - let config = GitConfig::new_with_config(None).unwrap(); + let config = GitConfig::default(); assert_eq!(config.editor, "git-editor"); }, ); @@ -196,7 +223,7 @@ mod tests { EnvVarAction::Set("VISUAL", String::from("visual-editor")), ], || { - let config = GitConfig::new_with_config(None).unwrap(); + let config = GitConfig::default(); assert_eq!(config.editor, "visual-editor"); }, ); @@ -211,7 +238,7 @@ mod tests { EnvVarAction::Set("EDITOR", String::from("editor")), ], || { - let config = GitConfig::new_with_config(None).unwrap(); + let config = GitConfig::default(); assert_eq!(config.editor, "editor"); }, ); @@ -227,7 +254,7 @@ mod tests { ], || { with_git_config(&["[core]", "editor = custom"], |git_config| { - let config = GitConfig::new_with_config(Some(&git_config)).unwrap(); + let config = GitConfig::new_with_config(&git_config).unwrap(); assert_eq!(config.editor, "custom"); }); }, @@ -238,7 +265,7 @@ mod tests { fn diff_rename_limit_invalid() { with_git_config(&["[diff]", "renameLimit = invalid"], |git_config| { assert_err_eq!( - GitConfig::new_with_config(Some(&git_config)), + GitConfig::new_with_config(&git_config), ConfigError::new("diff.renameLimit", "invalid", ConfigErrorCause::InvalidUnsignedInteger), ); }); @@ -248,7 +275,7 @@ mod tests { fn diff_rename_limit_invalid_range() { with_git_config(&["[diff]", "renameLimit = -100"], |git_config| { assert_err_eq!( - GitConfig::new_with_config(Some(&git_config)), + GitConfig::new_with_config(&git_config), ConfigError::new("diff.renameLimit", "-100", ConfigErrorCause::InvalidUnsignedInteger), ); }); @@ -258,7 +285,7 @@ mod tests { fn diff_renames_invalid() { with_git_config(&["[diff]", "renames = invalid"], |git_config| { assert_err_eq!( - GitConfig::new_with_config(Some(&git_config)), + GitConfig::new_with_config(&git_config), ConfigError::new("diff.renames", "invalid", ConfigErrorCause::InvalidDiffRenames), ); }); @@ -277,7 +304,7 @@ mod tests { &["[core]", format!("editor = {}", invalid_utf()).as_str()], |git_config| { assert_err_eq!( - GitConfig::new_with_config(Some(&git_config)), + GitConfig::new_with_config(&git_config), ConfigError::new_read_error("core.editor", ConfigErrorCause::InvalidUtf), ); }, @@ -292,7 +319,7 @@ mod tests { &["[core]", format!("commentChar = {}", invalid_utf()).as_str()], |git_config| { assert_err_eq!( - GitConfig::new_with_config(Some(&git_config)), + GitConfig::new_with_config(&git_config), ConfigError::new_read_error("core.commentChar", ConfigErrorCause::InvalidUtf), ); }, @@ -303,7 +330,7 @@ mod tests { fn diff_context_invalid() { with_git_config(&["[diff]", "context = invalid"], |git_config| { assert_err_eq!( - GitConfig::new_with_config(Some(&git_config)), + GitConfig::new_with_config(&git_config), ConfigError::new("diff.context", "invalid", ConfigErrorCause::InvalidUnsignedInteger), ); }); @@ -313,7 +340,7 @@ mod tests { fn diff_context_invalid_range() { with_git_config(&["[diff]", "context = -100"], |git_config| { assert_err_eq!( - GitConfig::new_with_config(Some(&git_config)), + GitConfig::new_with_config(&git_config), ConfigError::new("diff.context", "-100", ConfigErrorCause::InvalidUnsignedInteger), ); }); @@ -323,7 +350,7 @@ mod tests { fn diff_interhunk_lines_invalid() { with_git_config(&["[diff]", "interHunkContext = invalid"], |git_config| { assert_err_eq!( - GitConfig::new_with_config(Some(&git_config)), + GitConfig::new_with_config(&git_config), ConfigError::new( "diff.interHunkContext", "invalid", @@ -337,7 +364,7 @@ mod tests { fn diff_interhunk_lines_invalid_range() { with_git_config(&["[diff]", "interHunkContext = -100"], |git_config| { assert_err_eq!( - GitConfig::new_with_config(Some(&git_config)), + GitConfig::new_with_config(&git_config), ConfigError::new( "diff.interHunkContext", "-100", diff --git a/src/config/key_bindings.rs b/src/config/key_bindings.rs index 8bceb13bf..2bd729fb5 100644 --- a/src/config/key_bindings.rs +++ b/src/config/key_bindings.rs @@ -116,7 +116,7 @@ pub(crate) struct KeyBindings { } impl KeyBindings { - pub(super) fn new_with_config(git_config: Option<&Config>) -> Result { + pub(super) fn new_with_config(git_config: &Config) -> Result { let confirm_no = get_input(git_config, "interactive-rebase-tool.inputConfirmNo", "n")? .iter() .map(|s| map_single_ascii_to_lower(s)) @@ -185,7 +185,62 @@ impl TryFrom<&Config> for KeyBindings { type Error = ConfigError; fn try_from(config: &Config) -> Result { - Self::new_with_config(Some(config)) + Self::new_with_config(config) + } +} + +impl Default for KeyBindings { + fn default() -> Self { + let to_owned = |s: &str| vec![s.to_owned()]; + Self { + abort: to_owned("q"), + action_break: to_owned("b"), + action_drop: to_owned("d"), + action_edit: to_owned("e"), + action_fixup: to_owned("f"), + action_pick: to_owned("p"), + action_reword: to_owned("r"), + action_squash: to_owned("s"), + confirm_no: to_owned("n"), + confirm_yes: to_owned("y"), + edit: to_owned("E"), + force_abort: to_owned("Q"), + force_rebase: to_owned("W"), + help: to_owned("?"), + insert_line: to_owned("I"), + duplicate_line: to_owned("Controld"), + move_down: to_owned("Down"), + move_end: to_owned("End"), + move_home: to_owned("Home"), + move_left: to_owned("Left"), + move_right: to_owned("Right"), + move_down_step: to_owned("PageDown"), + move_up_step: to_owned("PageUp"), + move_up: to_owned("Up"), + move_selection_down: to_owned("j"), + move_selection_up: to_owned("k"), + scroll_down: to_owned("Down"), + scroll_end: to_owned("End"), + scroll_home: to_owned("Home"), + scroll_left: to_owned("Left"), + scroll_right: to_owned("Right"), + scroll_up: to_owned("Up"), + scroll_step_down: to_owned("PageDown"), + scroll_step_up: to_owned("PageUp"), + open_in_external_editor: to_owned("!"), + rebase: to_owned("w"), + redo: to_owned("Controly"), + remove_line: to_owned("Delete"), + search_start: to_owned("/"), + search_next: to_owned("n"), + search_previous: to_owned("N"), + show_commit: to_owned("c"), + show_diff: to_owned("d"), + toggle_visual_mode: to_owned("v"), + undo: to_owned("Controlz"), + fixup_keep_message_with_editor: to_owned("U"), + fixup_keep_message: to_owned("u"), + } } } @@ -198,7 +253,7 @@ mod tests { macro_rules! config_test { ($key:ident, $config_name:literal, $default:literal) => { - let config = KeyBindings::new_with_config(None).unwrap(); + let config = KeyBindings::default(); let value = config.$key[0].as_str(); assert_eq!( value, @@ -213,7 +268,7 @@ mod tests { with_git_config( &["[interactive-rebase-tool]", config_value.as_str()], |git_config| { - let config = KeyBindings::new_with_config(Some(&git_config)).unwrap(); + let config = KeyBindings::new_with_config(&git_config).unwrap(); assert_eq!( config.$key[0].as_str(), "F255", diff --git a/src/config/theme.rs b/src/config/theme.rs index cc8369377..86e672326 100644 --- a/src/config/theme.rs +++ b/src/config/theme.rs @@ -8,7 +8,7 @@ use crate::{ git::Config, }; -fn get_color(config: Option<&Config>, name: &str, default: Color) -> Result { +fn get_color(config: &Config, name: &str, default: Color) -> Result { if let Some(value) = get_optional_string(config, name)? { Color::try_from(value.to_lowercase().as_str()).map_err(|invalid_color_error| { ConfigError::new( @@ -75,7 +75,7 @@ pub(crate) struct Theme { impl Theme { /// Create a new theme from a Git Config reference. - pub(crate) fn new_with_config(git_config: Option<&Config>) -> Result { + pub(crate) fn new_with_config(git_config: &Config) -> Result { Ok(Self { character_vertical_spacing: get_string( git_config, @@ -127,7 +127,36 @@ impl TryFrom<&Config> for Theme { type Error = ConfigError; fn try_from(config: &Config) -> Result { - Self::new_with_config(Some(config)) + Self::new_with_config(config) + } +} + +impl Default for Theme { + fn default() -> Self { + Self { + character_vertical_spacing: "~".to_owned(), + color_action_break: Color::LightWhite, + color_action_drop: Color::LightRed, + color_action_edit: Color::LightBlue, + color_action_exec: Color::LightWhite, + color_action_fixup: Color::LightMagenta, + color_action_pick: Color::LightGreen, + color_action_reword: Color::LightYellow, + color_action_squash: Color::LightCyan, + color_action_label: Color::DarkYellow, + color_action_reset: Color::DarkYellow, + color_action_merge: Color::DarkYellow, + color_action_update_ref: Color::DarkMagenta, + color_background: Color::Default, + color_diff_add: Color::LightGreen, + color_diff_change: Color::LightYellow, + color_diff_context: Color::LightWhite, + color_diff_remove: Color::LightRed, + color_diff_whitespace: Color::LightBlack, + color_foreground: Color::Default, + color_indicator: Color::LightCyan, + color_selected_background: Color::Index(237), + } } } @@ -144,7 +173,7 @@ mod tests { macro_rules! config_test { ($key:ident, $config_name:literal, $default:expr) => { - let config = Theme::new_with_config(None).unwrap(); + let config = Theme::default(); let value = config.$key; assert_eq!( value, @@ -159,7 +188,7 @@ mod tests { with_git_config( &["[interactive-rebase-tool]", config_value.as_str()], |git_config| { - let config = Theme::new_with_config(Some(&git_config)).unwrap(); + let config = Theme::new_with_config(&git_config).unwrap(); assert_eq!( config.$key, Color::Index(42), @@ -187,11 +216,11 @@ mod tests { #[test] fn character_vertical_spacing() { - assert_eq!(Theme::new_with_config(None).unwrap().character_vertical_spacing, "~"); + assert_eq!(Theme::default().character_vertical_spacing, "~"); with_git_config( &["[interactive-rebase-tool]", "verticalSpacingCharacter = \"X\""], |config| { - let theme = Theme::new_with_config(Some(&config)).unwrap(); + let theme = Theme::new_with_config(&config).unwrap(); assert_eq!(theme.character_vertical_spacing, "X"); }, ); @@ -226,7 +255,7 @@ mod tests { fn value_parsing_invalid_color() { with_git_config(&["[interactive-rebase-tool]", "breakColor = -2"], |git_config| { assert_err_eq!( - Theme::new_with_config(Some(&git_config)), + Theme::new_with_config(&git_config), ConfigError::new( "interactive-rebase-tool.breakColor", "-2", @@ -247,7 +276,7 @@ mod tests { ], |git_config| { assert_err_eq!( - Theme::new_with_config(Some(&git_config)), + Theme::new_with_config(&git_config), ConfigError::new_read_error( format!("interactive-rebase-tool.{key}").as_str(), ConfigErrorCause::InvalidUtf diff --git a/src/config/utils/get_bool.rs b/src/config/utils/get_bool.rs index f95a0d1fc..77c628cff 100644 --- a/src/config/utils/get_bool.rs +++ b/src/config/utils/get_bool.rs @@ -3,29 +3,20 @@ use crate::{ git::{Config, ErrorCode}, }; -pub(crate) fn get_bool(config: Option<&Config>, name: &str, default: bool) -> Result { - if let Some(cfg) = config { - match cfg.get_bool(name) { - Ok(v) => Ok(v), - Err(e) if e.code() == ErrorCode::NotFound => Ok(default), - Err(e) if e.message().contains("failed to parse") => { - Err(ConfigError::new_with_optional_input( - name, - get_optional_string(config, name).ok().flatten(), - ConfigErrorCause::InvalidBoolean, - )) - }, - Err(e) => { - Err(ConfigError::new_with_optional_input( - name, - get_optional_string(config, name).ok().flatten(), - ConfigErrorCause::UnknownError(String::from(e.message())), - )) - }, - } - } - else { - Ok(default) +pub(crate) fn get_bool(config: &Config, name: &str, default: bool) -> Result { + match config.get_bool(name) { + Ok(v) => Ok(v), + Err(e) if e.code() == ErrorCode::NotFound => Ok(default), + Err(e) if e.message().contains("failed to parse") => Err(ConfigError::new_with_optional_input( + name, + get_optional_string(config, name).ok().flatten(), + ConfigErrorCause::InvalidBoolean, + )), + Err(e) => Err(ConfigError::new_with_optional_input( + name, + get_optional_string(config, name).ok().flatten(), + ConfigErrorCause::UnknownError(String::from(e.message())), + )), } } @@ -39,21 +30,21 @@ mod tests { #[test] fn read_true() { with_git_config(&["[test]", "bool = true"], |git_config| { - assert_ok_eq!(get_bool(Some(&git_config), "test.bool", false), true); + assert_ok_eq!(get_bool(&git_config, "test.bool", false), true); }); } #[test] fn read_false() { with_git_config(&["[test]", "bool = false"], |git_config| { - assert_ok_eq!(get_bool(Some(&git_config), "test.bool", true), false); + assert_ok_eq!(get_bool(&git_config, "test.bool", true), false); }); } #[test] fn read_default() { with_git_config(&[], |git_config| { - assert_ok_eq!(get_bool(Some(&git_config), "test.bool", true), true); + assert_ok_eq!(get_bool(&git_config, "test.bool", true), true); }); } @@ -61,7 +52,7 @@ mod tests { fn read_invalid_value() { with_git_config(&["[test]", "bool = invalid"], |git_config| { assert_err_eq!( - get_bool(Some(&git_config), "test.bool", true), + get_bool(&git_config, "test.bool", true), ConfigError::new("test.bool", "invalid", ConfigErrorCause::InvalidBoolean) ); }); @@ -71,7 +62,7 @@ mod tests { fn read_unexpected_error() { with_git_config(&["[test]", "bool = invalid"], |git_config| { assert_err_eq!( - get_bool(Some(&git_config), "test", true), + get_bool(&git_config, "test", true), ConfigError::new_read_error( "test", ConfigErrorCause::UnknownError(String::from("invalid config item name 'test'")) @@ -86,7 +77,7 @@ mod tests { &["[test]", format!("bool = {}", invalid_utf()).as_str()], |git_config| { assert_err_eq!( - get_bool(Some(&git_config), "test.bool", true), + get_bool(&git_config, "test.bool", true), ConfigError::new_read_error("test.bool", ConfigErrorCause::InvalidBoolean) ); }, diff --git a/src/config/utils/get_diff_ignore_whitespace.rs b/src/config/utils/get_diff_ignore_whitespace.rs index ea713ce37..8893f16ba 100644 --- a/src/config/utils/get_diff_ignore_whitespace.rs +++ b/src/config/utils/get_diff_ignore_whitespace.rs @@ -1,23 +1,20 @@ use crate::{ - config::{ConfigError, ConfigErrorCause, DiffIgnoreWhitespaceSetting, utils::get_string}, + config::{ConfigError, ConfigErrorCause, DiffIgnoreWhitespaceSetting, utils::get_optional_string}, git::Config, }; pub(crate) fn get_diff_ignore_whitespace( - git_config: Option<&Config>, + git_config: &Config, name: &str, ) -> Result { - match get_string(git_config, name, "none")?.to_lowercase().as_str() { - "true" | "on" | "all" => Ok(DiffIgnoreWhitespaceSetting::All), - "change" => Ok(DiffIgnoreWhitespaceSetting::Change), - "false" | "off" | "none" => Ok(DiffIgnoreWhitespaceSetting::None), - input => { - Err(ConfigError::new( + if let Some(config_value) = get_optional_string(git_config, name)? { + DiffIgnoreWhitespaceSetting::parse(&config_value).ok_or_else(|| ConfigError::new( name, - input, + &config_value, ConfigErrorCause::InvalidDiffIgnoreWhitespace, )) - }, + } else { + Ok(DiffIgnoreWhitespaceSetting::None) } } @@ -40,7 +37,7 @@ mod tests { #[case::mixed_case("ChAnGe", DiffIgnoreWhitespaceSetting::Change)] fn read_ok(#[case] value: &str, #[case] expected: DiffIgnoreWhitespaceSetting) { with_git_config(&["[test]", format!("value = \"{value}\"").as_str()], |git_config| { - assert_ok_eq!(get_diff_ignore_whitespace(Some(&git_config), "test.value"), expected); + assert_ok_eq!(get_diff_ignore_whitespace(&git_config, "test.value"), expected); }); } @@ -48,7 +45,7 @@ mod tests { fn read_default() { with_git_config(&[], |git_config| { assert_ok_eq!( - get_diff_ignore_whitespace(Some(&git_config), "test.value"), + get_diff_ignore_whitespace(&git_config, "test.value"), DiffIgnoreWhitespaceSetting::None ); }); @@ -58,7 +55,7 @@ mod tests { fn read_invalid_value() { with_git_config(&["[test]", "value = invalid"], |git_config| { assert_err_eq!( - get_diff_ignore_whitespace(Some(&git_config), "test.value"), + get_diff_ignore_whitespace(&git_config, "test.value"), ConfigError::new("test.value", "invalid", ConfigErrorCause::InvalidDiffIgnoreWhitespace) ); }); @@ -70,7 +67,7 @@ mod tests { &["[test]", format!("value = {}", invalid_utf()).as_str()], |git_config| { assert_err_eq!( - get_diff_ignore_whitespace(Some(&git_config), "test.value"), + get_diff_ignore_whitespace(&git_config, "test.value"), ConfigError::new_read_error("test.value", ConfigErrorCause::InvalidUtf) ); }, diff --git a/src/config/utils/get_diff_rename.rs b/src/config/utils/get_diff_rename.rs index 723d4d6b9..24669ec22 100644 --- a/src/config/utils/get_diff_rename.rs +++ b/src/config/utils/get_diff_rename.rs @@ -3,7 +3,7 @@ use crate::{ git::Config, }; -pub(crate) fn git_diff_renames(git_config: Option<&Config>, name: &str) -> Result<(bool, bool), ConfigError> { +pub(crate) fn git_diff_renames(git_config: &Config, name: &str) -> Result<(bool, bool), ConfigError> { match get_string(git_config, name, "true")?.to_lowercase().as_str() { "true" => Ok((true, false)), "false" => Ok((false, false)), @@ -28,14 +28,14 @@ mod tests { #[case::mixed_case("CoPiEs", (true, true))] fn read_ok(#[case] value: &str, #[case] expected: (bool, bool)) { with_git_config(&["[test]", format!("value = \"{value}\"").as_str()], |git_config| { - assert_ok_eq!(git_diff_renames(Some(&git_config), "test.value"), expected); + assert_ok_eq!(git_diff_renames(&git_config, "test.value"), expected); }); } #[test] fn read_default() { with_git_config(&[], |git_config| { - assert_ok_eq!(git_diff_renames(Some(&git_config), "test.value"), (true, false)); + assert_ok_eq!(git_diff_renames(&git_config, "test.value"), (true, false)); }); } @@ -43,7 +43,7 @@ mod tests { fn read_invalid_value() { with_git_config(&["[test]", "value = invalid"], |git_config| { assert_err_eq!( - git_diff_renames(Some(&git_config), "test.value"), + git_diff_renames(&git_config, "test.value"), ConfigError::new("test.value", "invalid", ConfigErrorCause::InvalidDiffRenames) ); }); @@ -55,7 +55,7 @@ mod tests { &["[test]", format!("value = {}", invalid_utf()).as_str()], |git_config| { assert_err_eq!( - git_diff_renames(Some(&git_config), "test.value"), + git_diff_renames(&git_config, "test.value"), ConfigError::new_read_error("test.value", ConfigErrorCause::InvalidUtf) ); }, diff --git a/src/config/utils/get_diff_show_whitespace.rs b/src/config/utils/get_diff_show_whitespace.rs index b3ac69128..d1b5384fc 100644 --- a/src/config/utils/get_diff_show_whitespace.rs +++ b/src/config/utils/get_diff_show_whitespace.rs @@ -1,18 +1,17 @@ use crate::{ - config::{ConfigError, ConfigErrorCause, DiffShowWhitespaceSetting, get_string}, + config::{ConfigError, ConfigErrorCause, DiffShowWhitespaceSetting, utils::get_optional_string}, git::Config, }; pub(crate) fn get_diff_show_whitespace( - git_config: Option<&Config>, + git_config: &Config, name: &str, ) -> Result { - match get_string(git_config, name, "both")?.to_lowercase().as_str() { - "true" | "on" | "both" => Ok(DiffShowWhitespaceSetting::Both), - "trailing" => Ok(DiffShowWhitespaceSetting::Trailing), - "leading" => Ok(DiffShowWhitespaceSetting::Leading), - "false" | "off" | "none" => Ok(DiffShowWhitespaceSetting::None), - input => Err(ConfigError::new(name, input, ConfigErrorCause::InvalidShowWhitespace)), + if let Some(config_value) = get_optional_string(git_config, name)? { + DiffShowWhitespaceSetting::parse(&config_value) + .ok_or_else(|| ConfigError::new(name, &config_value, ConfigErrorCause::InvalidShowWhitespace)) + } else { + Ok(DiffShowWhitespaceSetting::Both) } } @@ -36,7 +35,7 @@ mod tests { #[case::mixed_case("lEaDiNg", DiffShowWhitespaceSetting::Leading)] fn read_ok(#[case] value: &str, #[case] expected: DiffShowWhitespaceSetting) { with_git_config(&["[test]", format!("value = \"{value}\"").as_str()], |git_config| { - assert_ok_eq!(get_diff_show_whitespace(Some(&git_config), "test.value"), expected); + assert_ok_eq!(get_diff_show_whitespace(&git_config, "test.value"), expected); }); } @@ -44,7 +43,7 @@ mod tests { fn read_default() { with_git_config(&[], |git_config| { assert_ok_eq!( - get_diff_show_whitespace(Some(&git_config), "test.value"), + get_diff_show_whitespace(&git_config, "test.value"), DiffShowWhitespaceSetting::Both ); }); @@ -54,7 +53,7 @@ mod tests { fn read_invalid_value() { with_git_config(&["[test]", "value = invalid"], |git_config| { assert_err_eq!( - get_diff_show_whitespace(Some(&git_config), "test.value"), + get_diff_show_whitespace(&git_config, "test.value"), ConfigError::new("test.value", "invalid", ConfigErrorCause::InvalidShowWhitespace) ); }); @@ -66,7 +65,7 @@ mod tests { &["[test]", format!("value = {}", invalid_utf()).as_str()], |git_config| { assert_err_eq!( - get_diff_show_whitespace(Some(&git_config), "test.value"), + get_diff_show_whitespace(&git_config, "test.value"), ConfigError::new_read_error("test.value", ConfigErrorCause::InvalidUtf) ); }, diff --git a/src/config/utils/get_input.rs b/src/config/utils/get_input.rs index 65110970e..6deff8472 100644 --- a/src/config/utils/get_input.rs +++ b/src/config/utils/get_input.rs @@ -4,7 +4,7 @@ use crate::{ }; #[expect(clippy::string_slice, reason = "Slice usage is guarded.")] -pub(crate) fn get_input(config: Option<&Config>, name: &str, default: &str) -> Result, ConfigError> { +pub(crate) fn get_input(config: &Config, name: &str, default: &str) -> Result, ConfigError> { let mut values = vec![]; let input = get_string(config, name, default)?; for mut value in input.split_whitespace().map(String::from) { @@ -124,7 +124,7 @@ mod tests { fn read_value(#[case] binding: &str, #[case] expected: &str) { with_git_config(&["[test]", format!("value = {binding}").as_str()], |git_config| { assert_ok_eq!( - get_input(Some(&git_config), "test.value", "x"), + get_input(&git_config, "test.value", "x"), expected.split(',').map(String::from).collect::>() ); }); @@ -133,7 +133,7 @@ mod tests { #[test] fn read_value_default() { with_git_config(&[], |git_config| { - assert_ok_eq!(get_input(Some(&git_config), "test.value", "x"), vec![String::from("x")]); + assert_ok_eq!(get_input(&git_config, "test.value", "x"), vec![String::from("x")]); }); } @@ -144,7 +144,7 @@ mod tests { fn read_value_invalid(#[case] binding: &str) { with_git_config(&["[test]", format!("value = {binding}").as_str()], |git_config| { assert_err_eq!( - get_input(Some(&git_config), "test.value", "x"), + get_input(&git_config, "test.value", "x"), ConfigError::new("test.value", binding, ConfigErrorCause::InvalidKeyBinding) ); }); @@ -156,7 +156,7 @@ mod tests { &["[test]", format!("value = {}", invalid_utf()).as_str()], |git_config| { assert_err_eq!( - get_input(Some(&git_config), "test.value", "x"), + get_input(&git_config, "test.value", "x"), ConfigError::new_read_error("test.value", ConfigErrorCause::InvalidUtf) ); }, diff --git a/src/config/utils/get_string.rs b/src/config/utils/get_string.rs index 0aae1b029..09476c5f6 100644 --- a/src/config/utils/get_string.rs +++ b/src/config/utils/get_string.rs @@ -3,29 +3,27 @@ use crate::{ git::{Config, ErrorCode}, }; -pub(crate) fn get_optional_string(config: Option<&Config>, name: &str) -> Result, ConfigError> { - let Some(cfg) = config - else { - return Ok(None); - }; - match cfg.get_string(name) { +pub(crate) fn get_optional_string(config: &Config, name: &str) -> Result, ConfigError> { + match config.get_string(name) { Ok(v) => Ok(Some(v)), Err(e) if e.code() == ErrorCode::NotFound => Ok(None), // detecting a UTF-8 error is tricky Err(e) if e.message() == "configuration value is not valid utf8" => { Err(ConfigError::new_read_error(name, ConfigErrorCause::InvalidUtf)) }, - Err(e) => { - Err(ConfigError::new_read_error( - name, - ConfigErrorCause::UnknownError(String::from(e.message())), - )) - }, + Err(e) => Err(ConfigError::new_read_error( + name, + ConfigErrorCause::UnknownError(String::from(e.message())), + )), } } -pub(crate) fn get_string(config: Option<&Config>, name: &str, default: &str) -> Result { - Ok(get_optional_string(config, name)?.unwrap_or_else(|| String::from(default))) +pub(crate) fn get_string(config: &Config, name: &str, default: &str) -> Result { + match get_optional_string(config, name) { + Ok(Some(v)) => Ok(v), + Ok(None) => Ok(String::from(default)), + Err(e) => Err(e), + } } #[cfg(test)] @@ -38,10 +36,7 @@ mod tests { #[test] fn read_value() { with_git_config(&["[test]", "value = foo"], |git_config| { - assert_ok_eq!( - get_string(Some(&git_config), "test.value", "default"), - String::from("foo") - ); + assert_ok_eq!(get_string(&git_config, "test.value", "default"), String::from("foo")); }); } @@ -49,7 +44,7 @@ mod tests { fn read_default() { with_git_config(&[], |git_config| { assert_ok_eq!( - get_string(Some(&git_config), "test.value", "default"), + get_string(&git_config, "test.value", "default"), String::from("default") ); }); @@ -59,7 +54,7 @@ mod tests { fn read_unexpected_error() { with_git_config(&["[test]", "value = invalid"], |git_config| { assert_err_eq!( - get_string(Some(&git_config), "test", "default"), + get_string(&git_config, "test", "default"), ConfigError::new_read_error( "test", ConfigErrorCause::UnknownError(String::from("invalid config item name 'test'")) @@ -74,7 +69,7 @@ mod tests { &["[test]", format!("value = {}", invalid_utf()).as_str()], |git_config| { assert_err_eq!( - get_string(Some(&git_config), "test.value", "default"), + get_string(&git_config, "test.value", "default"), ConfigError::new_read_error("test.value", ConfigErrorCause::InvalidUtf) ); }, diff --git a/src/config/utils/get_unsigned_integer.rs b/src/config/utils/get_unsigned_integer.rs index 0e59b6ce4..7a360ec32 100644 --- a/src/config/utils/get_unsigned_integer.rs +++ b/src/config/utils/get_unsigned_integer.rs @@ -3,37 +3,26 @@ use crate::{ git::{Config, ErrorCode}, }; -pub(crate) fn get_unsigned_integer(config: Option<&Config>, name: &str, default: u32) -> Result { - if let Some(cfg) = config { - match cfg.get_i32(name) { - Ok(v) => { - v.try_into().map_err(|_| { - ConfigError::new_with_optional_input( - name, - get_optional_string(config, name).ok().flatten(), - ConfigErrorCause::InvalidUnsignedInteger, - ) - }) - }, - Err(e) if e.code() == ErrorCode::NotFound => Ok(default), - Err(e) if e.message().contains("failed to parse") => { - Err(ConfigError::new_with_optional_input( - name, - get_optional_string(config, name).ok().flatten(), - ConfigErrorCause::InvalidUnsignedInteger, - )) - }, - Err(e) => { - Err(ConfigError::new_with_optional_input( - name, - get_optional_string(config, name).ok().flatten(), - ConfigErrorCause::UnknownError(String::from(e.message())), - )) - }, - } - } - else { - Ok(default) +pub(crate) fn get_unsigned_integer(config: &Config, name: &str, default: u32) -> Result { + match config.get_i32(name) { + Ok(v) => v.try_into().map_err(|_| { + ConfigError::new_with_optional_input( + name, + get_optional_string(config, name).ok().flatten(), + ConfigErrorCause::InvalidUnsignedInteger, + ) + }), + Err(e) if e.code() == ErrorCode::NotFound => Ok(default), + Err(e) if e.message().contains("failed to parse") => Err(ConfigError::new_with_optional_input( + name, + get_optional_string(config, name).ok().flatten(), + ConfigErrorCause::InvalidUnsignedInteger, + )), + Err(e) => Err(ConfigError::new_with_optional_input( + name, + get_optional_string(config, name).ok().flatten(), + ConfigErrorCause::UnknownError(String::from(e.message())), + )), } } @@ -47,14 +36,14 @@ mod tests { #[test] fn read_value() { with_git_config(&["[test]", "value = 42"], |git_config| { - assert_ok_eq!(get_unsigned_integer(Some(&git_config), "test.value", 24), 42); + assert_ok_eq!(get_unsigned_integer(&git_config, "test.value", 24), 42); }); } #[test] fn read_value_min() { with_git_config(&["[test]", "value = 0"], |git_config| { - assert_ok_eq!(get_unsigned_integer(Some(&git_config), "test.value", 24), 0); + assert_ok_eq!(get_unsigned_integer(&git_config, "test.value", 24), 0); }); } @@ -62,7 +51,7 @@ mod tests { fn read_value_max() { with_git_config(&["[test]", format!("value = {}", i32::MAX).as_str()], |git_config| { assert_ok_eq!( - get_unsigned_integer(Some(&git_config), "test.value", 24), + get_unsigned_integer(&git_config, "test.value", 24), i32::MAX as u32 // git only supports i32s, so use i32 max ); }); @@ -72,7 +61,7 @@ mod tests { fn read_value_too_small() { with_git_config(&["[test]", "value = -1"], |git_config| { assert_err_eq!( - get_unsigned_integer(Some(&git_config), "test.value", 24), + get_unsigned_integer(&git_config, "test.value", 24), ConfigError::new("test.value", "-1", ConfigErrorCause::InvalidUnsignedInteger) ); }); @@ -82,7 +71,7 @@ mod tests { fn read_value_too_small_i32() { with_git_config(&["[test]", format!("value = {}", i64::MIN).as_str()], |git_config| { assert_err_eq!( - get_unsigned_integer(Some(&git_config), "test.value", 24), + get_unsigned_integer(&git_config, "test.value", 24), ConfigError::new( "test.value", i64::MIN.to_string().as_str(), @@ -96,7 +85,7 @@ mod tests { fn read_value_too_large() { with_git_config(&["[test]", format!("value = {}", u64::MAX).as_str()], |git_config| { assert_err_eq!( - get_unsigned_integer(Some(&git_config), "test.value", 24), + get_unsigned_integer(&git_config, "test.value", 24), ConfigError::new( "test.value", u64::MAX.to_string().as_str(), @@ -109,7 +98,7 @@ mod tests { #[test] fn read_default() { with_git_config(&[], |git_config| { - assert_ok_eq!(get_unsigned_integer(Some(&git_config), "test.value", 24), 24); + assert_ok_eq!(get_unsigned_integer(&git_config, "test.value", 24), 24); }); } @@ -117,7 +106,7 @@ mod tests { fn read_invalid() { with_git_config(&["[test]", "value = invalid"], |git_config| { assert_err_eq!( - get_unsigned_integer(Some(&git_config), "test.value", 24), + get_unsigned_integer(&git_config, "test.value", 24), ConfigError::new("test.value", "invalid", ConfigErrorCause::InvalidUnsignedInteger) ); }); @@ -127,7 +116,7 @@ mod tests { fn read_unexpected_error() { with_git_config(&["[test]", "value = invalid"], |git_config| { assert_err_eq!( - get_unsigned_integer(Some(&git_config), "test", 24), + get_unsigned_integer(&git_config, "test", 24), ConfigError::new_read_error( "test", ConfigErrorCause::UnknownError(String::from("invalid config item name 'test'")) @@ -142,7 +131,7 @@ mod tests { &["[test]", format!("value = {}", invalid_utf()).as_str()], |git_config| { assert_err_eq!( - get_unsigned_integer(Some(&git_config), "test.value", 24), + get_unsigned_integer(&git_config, "test.value", 24), ConfigError::new_read_error("test.value", ConfigErrorCause::InvalidUnsignedInteger) ); }, diff --git a/src/display.rs b/src/display.rs index 1a6bf4950..43a767a3a 100644 --- a/src/display.rs +++ b/src/display.rs @@ -369,20 +369,16 @@ mod tests { use super::*; use crate::test_helpers::mocks; - fn create_theme() -> Theme { - Theme::new_with_config(None).unwrap() - } - #[test] fn draw_str() { - let mut display = Display::new(mocks::CrossTerm::new(), &create_theme()); + let mut display = Display::new(mocks::CrossTerm::new(), &Theme::default()); display.draw_str("Test String").unwrap(); assert_eq!(display.tui.get_output(), &["Test String"]); } #[test] fn clear() { - let mut display = Display::new(mocks::CrossTerm::new(), &create_theme()); + let mut display = Display::new(mocks::CrossTerm::new(), &Theme::default()); display.draw_str("Test String").unwrap(); display.set_dim(true).unwrap(); display.set_reverse(true).unwrap(); @@ -396,7 +392,7 @@ mod tests { #[test] fn refresh() { - let mut display = Display::new(mocks::CrossTerm::new(), &create_theme()); + let mut display = Display::new(mocks::CrossTerm::new(), &Theme::default()); display.refresh().unwrap(); assert!(!display.tui.is_dirty()); } @@ -536,7 +532,7 @@ mod tests { #[case] expected_foreground: CrosstermColor, #[case] expected_background: CrosstermColor, ) { - let mut display = Display::new(mocks::CrossTerm::new(), &create_theme()); + let mut display = Display::new(mocks::CrossTerm::new(), &Theme::default()); display.color(display_color, selected).unwrap(); assert!( display @@ -555,7 +551,7 @@ mod tests { #[case::dim_underline(true, true, false)] #[case::all_on(true, true, true)] fn style(#[case] dim: bool, #[case] underline: bool, #[case] reverse: bool) { - let mut display = Display::new(mocks::CrossTerm::new(), &create_theme()); + let mut display = Display::new(mocks::CrossTerm::new(), &Theme::default()); display.set_style(dim, underline, reverse).unwrap(); assert_eq!(display.tui.is_dimmed(), dim); assert_eq!(display.tui.is_underline(), underline); @@ -564,21 +560,21 @@ mod tests { #[test] fn get_window_size() { - let mut display = Display::new(mocks::CrossTerm::new(), &create_theme()); + let mut display = Display::new(mocks::CrossTerm::new(), &Theme::default()); display.tui.set_size(Size::new(12, 10)); assert_eq!(display.get_window_size(), Size::new(12, 10)); } #[test] fn ensure_at_line_start() { - let mut display = Display::new(mocks::CrossTerm::new(), &create_theme()); + let mut display = Display::new(mocks::CrossTerm::new(), &Theme::default()); display.ensure_at_line_start().unwrap(); assert_eq!(display.tui.get_position(), (0, 0)); } #[test] fn move_from_end_of_line() { - let mut display = Display::new(mocks::CrossTerm::new(), &create_theme()); + let mut display = Display::new(mocks::CrossTerm::new(), &Theme::default()); display.tui.set_size(Size::new(20, 10)); display.move_from_end_of_line(5).unwrap(); // character after the 15th character (0-indexed) @@ -587,14 +583,14 @@ mod tests { #[test] fn start() { - let mut display = Display::new(mocks::CrossTerm::new(), &create_theme()); + let mut display = Display::new(mocks::CrossTerm::new(), &Theme::default()); display.start().unwrap(); assert_eq!(display.tui.get_state(), mocks::CrosstermMockState::Normal); } #[test] fn end() { - let mut display = Display::new(mocks::CrossTerm::new(), &create_theme()); + let mut display = Display::new(mocks::CrossTerm::new(), &Theme::default()); display.end().unwrap(); assert_eq!(display.tui.get_state(), mocks::CrosstermMockState::Ended); } diff --git a/src/input/event_handler.rs b/src/input/event_handler.rs index 2fa79e8b8..b915588ad 100644 --- a/src/input/event_handler.rs +++ b/src/input/event_handler.rs @@ -162,7 +162,7 @@ mod tests { use rstest::rstest; use super::*; - use crate::{input::map_keybindings, test_helpers::create_test_keybindings}; + use crate::input::map_keybindings; #[rstest] #[case::standard(Event::Key(KeyEvent { @@ -177,7 +177,7 @@ mod tests { }), false)] #[case::other(Event::from('a'), false)] fn read_event_options_disabled(#[case] event: Event, #[case] handled: bool) { - let event_handler = EventHandler::new(create_test_keybindings()); + let event_handler = EventHandler::new(KeyBindings::default()); let result = event_handler.read_event(event, &InputOptions::empty(), |_, _| Event::from(KeyCode::Null)); if handled { @@ -201,7 +201,7 @@ mod tests { }), true)] #[case::other(Event::from('a'), false)] fn read_event_enabled(#[case] event: Event, #[case] handled: bool) { - let event_handler = EventHandler::new(create_test_keybindings()); + let event_handler = EventHandler::new(KeyBindings::default()); let result = event_handler.read_event(event, &InputOptions::all(), |_, _| Event::from(KeyCode::Null)); if handled { @@ -214,7 +214,7 @@ mod tests { #[test] fn none_event() { - let event_handler = EventHandler::new(create_test_keybindings()); + let event_handler = EventHandler::new(KeyBindings::default()); let result = event_handler.read_event(Event::None, &InputOptions::empty(), |_, _| Event::from(KeyCode::Null)); assert_eq!(result, Event::None); } @@ -226,7 +226,7 @@ mod tests { }), Event::from(StandardEvent::Kill))] #[case::other(Event::from('a'), Event::from(KeyCode::Null))] fn standard_inputs(#[case] event: Event, #[case] expected: Event) { - let event_handler = EventHandler::new(create_test_keybindings()); + let event_handler = EventHandler::new(KeyBindings::default()); let result = event_handler.read_event(event, &InputOptions::empty(), |_, _| Event::from(KeyCode::Null)); assert_eq!(result, expected); } @@ -242,7 +242,7 @@ mod tests { #[case::standard(Event::from(KeyCode::End), Event::from(StandardEvent::ScrollBottom))] #[case::other(Event::from('a'), Event::from(KeyCode::Null))] fn movement_inputs(#[case] event: Event, #[case] expected: Event) { - let event_handler = EventHandler::new(create_test_keybindings()); + let event_handler = EventHandler::new(KeyBindings::default()); let result = event_handler.read_event(event, &InputOptions::MOVEMENT, |_, _| Event::from(KeyCode::Null)); assert_eq!(result, expected); } @@ -258,7 +258,7 @@ mod tests { #[case::standard(Event::from(KeyCode::End), Event::from(StandardEvent::ScrollBottom))] #[case::other(Event::from('a'), Event::from(KeyCode::Null))] fn default_movement_inputs(#[case] event: Event, #[case] expected: Event) { - let mut bindings = create_test_keybindings(); + let mut bindings = KeyBindings::default(); bindings.scroll_down = map_keybindings(&[String::from("x")]); bindings.scroll_end = map_keybindings(&[String::from("x")]); bindings.scroll_home = map_keybindings(&[String::from("x")]); @@ -280,7 +280,7 @@ mod tests { #[case::enter(Event::from(KeyCode::Enter), Event::from(StandardEvent::SearchFinish))] #[case::other(Event::from('a'), Event::from(KeyCode::Null))] fn search_inputs(#[case] event: Event, #[case] expected: Event) { - let event_handler = EventHandler::new(create_test_keybindings()); + let event_handler = EventHandler::new(KeyBindings::default()); let result = event_handler.read_event(event, &InputOptions::SEARCH, |_, _| Event::from(KeyCode::Null)); assert_eq!(result, expected); } @@ -289,14 +289,14 @@ mod tests { #[case::search_start(Event::from('/'), Event::from(StandardEvent::SearchStart))] #[case::other(Event::from('a'), Event::from(KeyCode::Null))] fn search_start(#[case] event: Event, #[case] expected: Event) { - let event_handler = EventHandler::new(create_test_keybindings()); + let event_handler = EventHandler::new(KeyBindings::default()); let result = event_handler.read_event(event, &InputOptions::SEARCH_START, |_, _| Event::from(KeyCode::Null)); assert_eq!(result, expected); } #[test] fn help_event() { - let event_handler = EventHandler::new(create_test_keybindings()); + let event_handler = EventHandler::new(KeyBindings::default()); let result = event_handler.read_event(Event::from('?'), &InputOptions::HELP, |_, _| Event::from(KeyCode::Null)); assert_eq!(result, Event::from(StandardEvent::Help)); } @@ -312,7 +312,7 @@ mod tests { }), Event::from(StandardEvent::Redo))] #[case::other(Event::from('a'), Event::from(KeyCode::Null))] fn undo_redo_inputs(#[case] event: Event, #[case] expected: Event) { - let event_handler = EventHandler::new(create_test_keybindings()); + let event_handler = EventHandler::new(KeyBindings::default()); let result = event_handler.read_event(event, &InputOptions::UNDO_REDO, |_, _| Event::from(KeyCode::Null)); assert_eq!(result, expected); } diff --git a/src/input/key_bindings.rs b/src/input/key_bindings.rs index 33542fa8e..949569c06 100644 --- a/src/input/key_bindings.rs +++ b/src/input/key_bindings.rs @@ -157,6 +157,13 @@ impl KeyBindings { } } +impl Default for KeyBindings { + fn default() -> Self { + let default_config = crate::config::KeyBindings::default(); + Self::new(&default_config) + } +} + #[cfg(test)] mod tests { use crossterm::event::{KeyCode, KeyModifiers}; diff --git a/src/module/module_handler.rs b/src/module/module_handler.rs index 1b002c038..d912e7fbe 100644 --- a/src/module/module_handler.rs +++ b/src/module/module_handler.rs @@ -115,7 +115,7 @@ mod tests { #[test] fn module_lifecycle() { - testers::module(&["pick aaa comment"], &[], None, |context| { + testers::module(&["pick aaa comment"], &[], |context| { let test_module = TestModule::new(); let mut module_handler = ModuleHandler::new( context.event_handler_context.event_handler, @@ -132,7 +132,7 @@ mod tests { #[test] fn error() { - testers::module(&["pick aaa comment"], &[], None, |context| { + testers::module(&["pick aaa comment"], &[], |context| { let test_module = TestModule::new(); let mut module_handler = ModuleHandler::new( context.event_handler_context.event_handler, diff --git a/src/module/modules.rs b/src/module/modules.rs index f1e63430b..9183f42b7 100644 --- a/src/module/modules.rs +++ b/src/module/modules.rs @@ -64,11 +64,12 @@ mod tests { use super::*; use crate::{ + config::Config, diff, diff::CommitDiff, input, search, - test_helpers::{create_config, with_todo_file}, + test_helpers::with_todo_file, view, }; @@ -77,7 +78,7 @@ mod tests { with_todo_file(&[], |todo_file_context| { let commit_diff = CommitDiff::new(); let (_todo_file_path, todo_file) = todo_file_context.to_owned(); - let config = create_config(); + let config = Config::default(); let app_data = AppData::new( config, State::WindowSizeError, diff --git a/src/module/tests.rs b/src/module/tests.rs index d1ce5e902..92fb9de84 100644 --- a/src/module/tests.rs +++ b/src/module/tests.rs @@ -1,8 +1,9 @@ use anyhow::anyhow; use crate::{ + input::KeyBindings, module::{Event, InputOptions, Module, State}, - test_helpers::{create_test_keybindings, testers}, + test_helpers::testers, }; struct TestModule; @@ -23,7 +24,7 @@ fn default_trait_method_deactivate() { #[test] fn default_trait_method_build_view_data() { - testers::module(&[], &[], None, |context| { + testers::module(&[], &[], |context| { let mut module = TestModule {}; let view_data = module.build_view_data(&context.render_context); assert!(!view_data.get_name().is_empty()); @@ -38,9 +39,8 @@ fn default_trait_method_input_options() { #[test] fn default_trait_method_read_event() { - let key_bindings = create_test_keybindings(); let module = TestModule {}; - assert_eq!(module.read_event(Event::from('a'), &key_bindings), Event::from('a')); + assert_eq!(module.read_event(Event::from('a'), &KeyBindings::default()), Event::from('a')); } #[test] diff --git a/src/modules/confirm_abort.rs b/src/modules/confirm_abort.rs index 6c6c4f37e..baba6c80d 100644 --- a/src/modules/confirm_abort.rs +++ b/src/modules/confirm_abort.rs @@ -69,12 +69,12 @@ mod tests { assert_results, input::{KeyCode, StandardEvent}, process::Artifact, - test_helpers::{assertions::assert_rendered_output::AssertRenderOptions, testers}, + test_helpers::{assertions::assert_rendered_output::AssertRenderOptions, testers} }; #[test] fn build_view_data() { - testers::module(&["pick aaa comment"], &[], None, |test_context| { + testers::module(&["pick aaa comment"], &[], |test_context| { let mut module = ConfirmAbort::new(&test_context.app_data()); let view_data = test_context.build_view_data(&mut module); assert_rendered_output!( @@ -91,7 +91,6 @@ mod tests { testers::module( &["pick aaa comment"], &[Event::from(StandardEvent::Yes)], - None, |mut test_context| { let mut module = ConfirmAbort::new(&test_context.app_data()); assert_results!( @@ -109,7 +108,6 @@ mod tests { testers::module( &["pick aaa comment"], &[Event::from(StandardEvent::No)], - None, |mut test_context| { let mut module = ConfirmAbort::new(&test_context.app_data()); assert_results!( @@ -126,7 +124,6 @@ mod tests { testers::module( &["pick aaa comment"], &[Event::from(KeyCode::Null)], - None, |mut test_context| { let mut module = ConfirmAbort::new(&test_context.app_data()); assert_results!( diff --git a/src/modules/confirm_rebase.rs b/src/modules/confirm_rebase.rs index 747de16f7..c4adecf19 100644 --- a/src/modules/confirm_rebase.rs +++ b/src/modules/confirm_rebase.rs @@ -65,7 +65,7 @@ mod tests { #[test] fn build_view_data() { - testers::module(&["pick aaa comment"], &[], None, |test_context| { + testers::module(&["pick aaa comment"], &[], |test_context| { let mut module = ConfirmRebase::new(&test_context.app_data()); let view_data = test_context.build_view_data(&mut module); assert_rendered_output!( @@ -82,9 +82,7 @@ mod tests { fn handle_event_yes() { testers::module( &["pick aaa comment"], - &[Event::from(StandardEvent::Yes)], - None, - |mut test_context| { + &[Event::from(StandardEvent::Yes)], |mut test_context| { let mut module = ConfirmRebase::new(&test_context.app_data()); assert_results!( test_context.handle_event(&mut module), @@ -99,9 +97,7 @@ mod tests { fn handle_event_no() { testers::module( &["pick aaa comment"], - &[Event::from(StandardEvent::No)], - None, - |mut test_context| { + &[Event::from(StandardEvent::No)], |mut test_context| { let mut module = ConfirmRebase::new(&test_context.app_data()); assert_results!( test_context.handle_event(&mut module), @@ -116,9 +112,7 @@ mod tests { fn handle_event_no_match_key() { testers::module( &["pick aaa comment"], - &[Event::from(KeyCode::Null)], - None, - |mut test_context| { + &[Event::from(KeyCode::Null)], |mut test_context| { let mut module = ConfirmRebase::new(&test_context.app_data()); assert_results!( test_context.handle_event(&mut module), diff --git a/src/modules/error.rs b/src/modules/error.rs index cdfee0378..52c8f586b 100644 --- a/src/modules/error.rs +++ b/src/modules/error.rs @@ -90,7 +90,7 @@ mod tests { #[test] fn simple_error() { - testers::module(&[], &[], None, |test_context| { + testers::module(&[], &[], |test_context| { let mut module = Error::new(&test_context.app_data()); _ = module.handle_error(&anyhow!("Test Error")); let view_data = test_context.build_view_data(&mut module); @@ -107,7 +107,7 @@ mod tests { #[test] fn error_with_contest() { - testers::module(&[], &[], None, |test_context| { + testers::module(&[], &[], |test_context| { let mut module = Error::new(&test_context.app_data()); _ = module.handle_error(&anyhow!("Test Error").context("Context")); let view_data = test_context.build_view_data(&mut module); @@ -121,7 +121,7 @@ mod tests { #[test] fn error_with_newlines() { - testers::module(&[], &[], None, |test_context| { + testers::module(&[], &[], |test_context| { let mut module = Error::new(&test_context.app_data()); _ = module.handle_error(&anyhow!("Test\nError").context("With\nContext")); let view_data = test_context.build_view_data(&mut module); @@ -137,7 +137,7 @@ mod tests { #[test] fn return_state() { - testers::module(&[], &[Event::from('a')], None, |mut test_context| { + testers::module(&[], &[Event::from('a')], |mut test_context| { let mut module = Error::new(&test_context.app_data()); _ = test_context.activate(&mut module, State::ConfirmRebase); _ = module.handle_error(&anyhow!("Test Error")); @@ -151,7 +151,7 @@ mod tests { #[test] fn resize() { - testers::module(&[], &[Event::Resize(100, 100)], None, |mut test_context| { + testers::module(&[], &[Event::Resize(100, 100)], |mut test_context| { let mut module = Error::new(&test_context.app_data()); _ = test_context.activate(&mut module, State::ConfirmRebase); _ = module.handle_error(&anyhow!("Test Error")); diff --git a/src/modules/external_editor/tests.rs b/src/modules/external_editor/tests.rs index 39eaf7c47..ff0aea5f5 100644 --- a/src/modules/external_editor/tests.rs +++ b/src/modules/external_editor/tests.rs @@ -4,9 +4,10 @@ use super::*; use crate::{ assert_rendered_output, assert_results, + config::Config, input::KeyCode, process::Artifact, - test_helpers::{create_config, testers, testers::ModuleTestContext}, + test_helpers::{testers, testers::ModuleTestContext}, }; fn assert_external_editor_state_eq(actual: &ExternalEditorState, expected: &ExternalEditorState) { @@ -55,12 +56,12 @@ fn todo_file_path(test_context: &ModuleTestContext) -> String { #[test] fn activate() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::from("editor"); - testers::module( + testers::module_with_config( &["pick aaa comment1", "drop bbb comment2"], &[], - Some(config), + config, |test_context| { let todo_path = todo_file_path(&test_context); @@ -82,7 +83,7 @@ fn activate() { #[test] fn activate_write_file_fail() { - testers::module(&["pick aaa comment"], &[], None, |test_context| { + testers::module(&["pick aaa comment"], &[], |test_context| { let todo_path = todo_file_path(&test_context); let file = File::open(todo_path.as_str()).unwrap(); let mut permissions = file.metadata().unwrap().permissions(); @@ -99,9 +100,9 @@ fn activate_write_file_fail() { #[test] fn activate_file_placement_marker() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::from("editor a % b"); - testers::module(&[], &[], Some(config), |test_context| { + testers::module_with_config(&[], &[], config, |test_context| { let todo_path = todo_file_path(&test_context); let mut module = ExternalEditor::new(&test_context.app_data()); assert_results!( @@ -117,12 +118,12 @@ fn activate_file_placement_marker() { #[test] fn deactivate() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::from("editor"); - testers::module( + testers::module_with_config( &["pick aaa comment", "drop bbb comment2"], &[], - Some(config), + config, |mut test_context| { let mut module = ExternalEditor::new(&test_context.app_data()); _ = test_context.deactivate(&mut module); @@ -133,12 +134,12 @@ fn deactivate() { #[test] fn edit_success() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::from("editor"); - testers::module( + testers::module_with_config( &["pick aaa comment"], &[Event::from(StandardEvent::ExternalCommandSuccess)], - Some(config), + config, |mut test_context| { let mut module = ExternalEditor::new(&test_context.app_data()); _ = test_context.activate(&mut module, State::List); @@ -156,12 +157,12 @@ fn edit_success() { #[test] fn empty_edit_error() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::from("editor"); - testers::module( + testers::module_with_config( &["pick aaa comment"], &[Event::from('1'), Event::from(StandardEvent::ExternalCommandSuccess)], - Some(config), + config, |mut test_context| { let mut module = ExternalEditor::new(&test_context.app_data()); _ = test_context.activate(&mut module, State::List); @@ -195,12 +196,12 @@ fn empty_edit_error() { #[test] fn empty_edit_abort_rebase() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::from("editor"); - testers::module( + testers::module_with_config( &["pick aaa comment"], &[Event::from('1')], - Some(config), + config, |mut test_context| { let mut module = ExternalEditor::new(&test_context.app_data()); _ = test_context.activate(&mut module, State::List); @@ -216,13 +217,13 @@ fn empty_edit_abort_rebase() { #[test] fn empty_edit_re_edit_rebase_file() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::from("editor"); - testers::module( + testers::module_with_config( &["pick aaa comment"], &[Event::from('2')], - Some(config), + config, |mut test_context| { let todo_path = todo_file_path(&test_context); let mut module = ExternalEditor::new(&test_context.app_data()); @@ -240,12 +241,12 @@ fn empty_edit_re_edit_rebase_file() { #[test] fn empty_edit_undo_and_edit() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::from("editor"); - testers::module( + testers::module_with_config( &["pick aaa comment", "drop bbb comment"], &[Event::from('3')], - Some(config), + config, |mut test_context| { let todo_path = todo_file_path(&test_context); let mut module = ExternalEditor::new(&test_context.app_data()); @@ -267,9 +268,9 @@ fn empty_edit_undo_and_edit() { #[test] fn empty_edit_noop() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::from("editor"); - testers::module(&["pick aaa comment"], &[], Some(config), |test_context| { + testers::module_with_config(&["pick aaa comment"], &[], config, |test_context| { let mut module = ExternalEditor::new(&test_context.app_data()); _ = test_context.activate(&mut module, State::List); module.todo_file.lock().set_lines(vec![]); @@ -293,9 +294,9 @@ fn empty_edit_noop() { #[test] fn no_editor_set() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::new(); - testers::module(&["pick aaa comment"], &[], Some(config), |test_context| { + testers::module_with_config(&["pick aaa comment"], &[], config, |test_context| { let mut module = ExternalEditor::new(&test_context.app_data()); assert_results!( test_context.activate(&mut module, State::List), @@ -309,12 +310,12 @@ fn no_editor_set() { #[test] fn editor_non_zero_exit() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::from("editor"); - testers::module( + testers::module_with_config( &["pick aaa comment"], &[Event::from(StandardEvent::ExternalCommandError)], - Some(config), + config, |mut test_context| { let mut module = ExternalEditor::new(&test_context.app_data()); @@ -348,15 +349,15 @@ fn editor_non_zero_exit() { #[test] fn editor_reload_error() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::from("editor"); - testers::module( + testers::module_with_config( &["pick aaa comment"], &[ Event::from(KeyCode::Up), Event::from(StandardEvent::ExternalCommandSuccess), ], - Some(config), + config, |mut test_context| { let todo_path = todo_file_path(&test_context); let path = Path::new(todo_path.as_str()); @@ -394,13 +395,13 @@ fn editor_reload_error() { #[test] fn error_abort_rebase() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::from("editor"); - testers::module( + testers::module_with_config( &["pick aaa comment"], &[Event::from('1')], - Some(config), + config, |mut test_context| { let mut module = ExternalEditor::new(&test_context.app_data()); _ = test_context.activate(&mut module, State::List); @@ -417,12 +418,12 @@ fn error_abort_rebase() { #[test] fn error_edit_rebase() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::from("editor"); - testers::module( + testers::module_with_config( &["pick aaa comment"], &[Event::from('2')], - Some(config), + config, |mut test_context| { let todo_path = todo_file_path(&test_context); let mut module = ExternalEditor::new(&test_context.app_data()); @@ -440,12 +441,12 @@ fn error_edit_rebase() { #[test] fn error_restore_and_abort() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::from("editor"); - testers::module( + testers::module_with_config( &["pick aaa comment"], &[Event::from('3')], - Some(config), + config, |mut test_context| { let mut module = ExternalEditor::new(&test_context.app_data()); _ = test_context.activate(&mut module, State::List); @@ -464,12 +465,12 @@ fn error_restore_and_abort() { #[test] fn error_undo_modifications_and_reedit() { - let mut config = create_config(); + let mut config = Config::default(); config.git.editor = String::from("editor"); - testers::module( + testers::module_with_config( &["pick aaa comment"], &[Event::from('4')], - Some(config), + config, |mut test_context| { let todo_path = todo_file_path(&test_context); let mut module = ExternalEditor::new(&test_context.app_data()); diff --git a/src/modules/insert/tests.rs b/src/modules/insert/tests.rs index 3b170d65b..4efa3f2d9 100644 --- a/src/modules/insert/tests.rs +++ b/src/modules/insert/tests.rs @@ -3,7 +3,7 @@ use crate::{assert_rendered_output, assert_results, input::KeyCode, process::Art #[test] fn activate() { - testers::module(&[], &[], None, |test_context| { + testers::module(&[], &[], |test_context| { let mut module = Insert::new(&test_context.app_data()); assert_results!(test_context.activate(&mut module, State::List)); }); @@ -11,7 +11,7 @@ fn activate() { #[test] fn render_prompt() { - testers::module(&[], &[], None, |test_context| { + testers::module(&[], &[], |test_context| { let mut module = Insert::new(&test_context.app_data()); let view_data = test_context.build_view_data(&mut module); assert_rendered_output!( @@ -36,7 +36,7 @@ fn render_prompt() { #[test] fn prompt_cancel() { - testers::module(&[], &[Event::from('q')], None, |mut test_context| { + testers::module(&[], &[Event::from('q')], |mut test_context| { let mut module = Insert::new(&test_context.app_data()); assert_results!( test_context.handle_event(&mut module), @@ -57,7 +57,6 @@ fn edit_render_exec() { Event::from('o'), Event::from(KeyCode::Enter), ], - None, |mut test_context| { let mut module = Insert::new(&test_context.app_data()); _ = test_context.handle_n_events(&mut module, 4); @@ -94,7 +93,6 @@ fn edit_render_pick() { Event::from('c'), Event::from(KeyCode::Enter), ], - None, |mut test_context| { let mut module = Insert::new(&test_context.app_data()); _ = test_context.handle_n_events(&mut module, 4); @@ -131,7 +129,6 @@ fn edit_render_label() { Event::from('o'), Event::from(KeyCode::Enter), ], - None, |mut test_context| { let mut module = Insert::new(&test_context.app_data()); _ = test_context.handle_n_events(&mut module, 4); @@ -168,7 +165,6 @@ fn edit_render_reset() { Event::from('o'), Event::from(KeyCode::Enter), ], - None, |mut test_context| { let mut module = Insert::new(&test_context.app_data()); _ = test_context.handle_n_events(&mut module, 4); @@ -205,7 +201,6 @@ fn edit_render_merge() { Event::from('o'), Event::from(KeyCode::Enter), ], - None, |mut test_context| { let mut module = Insert::new(&test_context.app_data()); _ = test_context.handle_n_events(&mut module, 4); @@ -242,7 +237,6 @@ fn update_ref_render_merge() { Event::from('o'), Event::from(KeyCode::Enter), ], - None, |mut test_context| { let mut module = Insert::new(&test_context.app_data()); _ = test_context.handle_n_events(&mut module, 4); @@ -279,7 +273,6 @@ fn edit_select_next_index() { Event::from('o'), Event::from(KeyCode::Enter), ], - None, |mut test_context| { let mut module = Insert::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -293,7 +286,6 @@ fn cancel_edit() { testers::module( &[], &[Event::from('e'), Event::from(KeyCode::Enter)], - None, |mut test_context| { let mut module = Insert::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); diff --git a/src/modules/list/tests.rs b/src/modules/list/tests.rs index 092a35fda..fa1e73147 100644 --- a/src/modules/list/tests.rs +++ b/src/modules/list/tests.rs @@ -20,14 +20,14 @@ mod undo_redo; mod visual_mode; use super::*; -use crate::test_helpers::{create_config, testers}; +use crate::test_helpers::testers; +use crate::config::Config; #[test] fn resize() { testers::module( &["pick aaa c1"], &[Event::Resize(100, 200)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); diff --git a/src/modules/list/tests/abort_and_rebase.rs b/src/modules/list/tests/abort_and_rebase.rs index 8e433b3f4..590b0ec75 100644 --- a/src/modules/list/tests/abort_and_rebase.rs +++ b/src/modules/list/tests/abort_and_rebase.rs @@ -6,7 +6,6 @@ fn normal_mode_abort() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::Abort)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( @@ -26,7 +25,6 @@ fn visual_mode_abort() { Event::from(StandardEvent::ToggleVisualMode), Event::from(StandardEvent::Abort), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_event(&mut module); @@ -44,7 +42,6 @@ fn normal_mode_force_abort() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::ForceAbort)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( @@ -65,7 +62,6 @@ fn visual_mode_force_abort() { Event::from(StandardEvent::ToggleVisualMode), Event::from(StandardEvent::ForceAbort), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_event(&mut module); @@ -84,7 +80,6 @@ fn normal_mode_rebase() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::Rebase)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( @@ -104,7 +99,6 @@ fn visual_mode_rebase() { Event::from(StandardEvent::ToggleVisualMode), Event::from(StandardEvent::Rebase), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_event(&mut module); @@ -122,7 +116,6 @@ fn normal_mode_force_rebase() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::ForceRebase)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( @@ -143,7 +136,6 @@ fn visual_mode_force_rebase() { Event::from(StandardEvent::ToggleVisualMode), Event::from(StandardEvent::ForceRebase), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_event(&mut module); diff --git a/src/modules/list/tests/activate.rs b/src/modules/list/tests/activate.rs index 743c6ae06..03fe4298a 100644 --- a/src/modules/list/tests/activate.rs +++ b/src/modules/list/tests/activate.rs @@ -20,7 +20,7 @@ impl Searchable for MockedSearchable { #[test] fn sets_selected_line_action() { - testers::module(&["pick aaa c1"], &[], None, |test_context| { + testers::module(&["pick aaa c1"], &[], |test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.activate(&mut module, State::List); assert_some_eq!(module.selected_line_action, Action::Pick); @@ -29,7 +29,7 @@ fn sets_selected_line_action() { #[test] fn sets_selected_line_action_none_selected() { - testers::module(&["pick aaa c1", "pick bbb c2"], &[], None, |test_context| { + testers::module(&["pick aaa c1", "pick bbb c2"], &[], |test_context| { let app_data = test_context.app_data(); let todo_file = app_data.todo_file(); @@ -43,7 +43,7 @@ fn sets_selected_line_action_none_selected() { #[test] fn result() { - testers::module(&["pick aaa c1", "pick bbb c2"], &[], None, |test_context| { + testers::module(&["pick aaa c1", "pick bbb c2"], &[], |test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( test_context.activate(&mut module, State::List), @@ -54,7 +54,7 @@ fn result() { #[test] fn result_with_serach_term() { - testers::module(&["pick aaa c1", "pick bbb c2"], &[], None, |test_context| { + testers::module(&["pick aaa c1", "pick bbb c2"], &[], |test_context| { let mut module = List::new(&test_context.app_data()); module.search_bar.start_search(Some("foo")); assert_results!( diff --git a/src/modules/list/tests/change_action.rs b/src/modules/list/tests/change_action.rs index 250cf08a7..4ce595e60 100644 --- a/src/modules/list/tests/change_action.rs +++ b/src/modules/list/tests/change_action.rs @@ -6,7 +6,6 @@ fn normal_mode_action_change_to_drop() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::ActionDrop)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -33,7 +32,6 @@ fn visual_mode_action_change_to_drop() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::ActionDrop), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -55,7 +53,6 @@ fn normal_mode_action_change_to_edit() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::ActionEdit)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -85,7 +82,6 @@ fn visual_mode_action_change_to_edit() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::ActionEdit), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -107,7 +103,6 @@ fn normal_mode_action_change_to_fixup() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::ActionFixup)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -137,7 +132,6 @@ fn visual_mode_action_change_to_fixup() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::ActionFixup), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -159,7 +153,6 @@ fn normal_mode_action_change_to_pick() { testers::module( &["drop aaa c1"], &[Event::from(StandardEvent::ActionPick)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -189,7 +182,6 @@ fn visual_mode_action_change_to_pick() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::ActionPick), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -211,7 +203,6 @@ fn normal_mode_action_change_to_reword() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::ActionReword)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -241,7 +232,6 @@ fn visual_mode_action_change_to_reword() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::ActionReword), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -263,7 +253,6 @@ fn normal_mode_action_change_to_squash() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::ActionSquash)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -292,7 +281,6 @@ fn visual_mode_action_change_to_squash() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::ActionSquash), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); diff --git a/src/modules/list/tests/duplicate_line.rs b/src/modules/list/tests/duplicate_line.rs index 5942dce72..5c2e85956 100644 --- a/src/modules/list/tests/duplicate_line.rs +++ b/src/modules/list/tests/duplicate_line.rs @@ -6,7 +6,6 @@ fn duplicate_line_duplicatable() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::DuplicateLine)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( @@ -27,7 +26,6 @@ fn duplicate_line_not_duplicatable() { testers::module( &["break"], &[Event::from(StandardEvent::DuplicateLine)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( diff --git a/src/modules/list/tests/edit_mode.rs b/src/modules/list/tests/edit_mode.rs index 804513785..e5a1d2971 100644 --- a/src/modules/list/tests/edit_mode.rs +++ b/src/modules/list/tests/edit_mode.rs @@ -6,7 +6,6 @@ fn edit_with_edit_content() { testers::module( &["exec echo foo"], &[Event::from(StandardEvent::Edit)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( @@ -23,7 +22,6 @@ fn edit_without_edit_content() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::Edit)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( @@ -37,7 +35,7 @@ fn edit_without_edit_content() { #[test] fn edit_without_selected_line() { - testers::module(&[], &[Event::from(StandardEvent::Edit)], None, |mut test_context| { + testers::module(&[], &[Event::from(StandardEvent::Edit)], |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( test_context.handle_event(&mut module), @@ -56,7 +54,6 @@ fn handle_event() { Event::from(KeyCode::Backspace), Event::from(KeyCode::Enter), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.build_view_data(&mut module); @@ -72,7 +69,6 @@ fn render() { testers::module( &["exec foo"], &[Event::from(StandardEvent::Edit)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); diff --git a/src/modules/list/tests/external_editor.rs b/src/modules/list/tests/external_editor.rs index 4da693bff..c8c382ee6 100644 --- a/src/modules/list/tests/external_editor.rs +++ b/src/modules/list/tests/external_editor.rs @@ -6,7 +6,6 @@ fn normal_mode_open_external_editor() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::OpenInEditor)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( @@ -27,7 +26,6 @@ fn visual_mode_open_external_editor() { Event::from(StandardEvent::ToggleVisualMode), Event::from(StandardEvent::OpenInEditor), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_event(&mut module); diff --git a/src/modules/list/tests/help.rs b/src/modules/list/tests/help.rs index aa828780a..3c860bc85 100644 --- a/src/modules/list/tests/help.rs +++ b/src/modules/list/tests/help.rs @@ -6,7 +6,6 @@ fn normal_mode_help() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::Help)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); module.state = ListState::Normal; @@ -61,7 +60,6 @@ fn normal_mode_help_event() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::Help), Event::from(KeyCode::Enter)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); module.state = ListState::Normal; @@ -76,7 +74,6 @@ fn visual_mode_help() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::Help)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); module.state = ListState::Visual; @@ -126,7 +123,6 @@ fn visual_mode_help_event() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::Help), Event::from(KeyCode::Enter)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); module.state = ListState::Visual; diff --git a/src/modules/list/tests/insert_line.rs b/src/modules/list/tests/insert_line.rs index 1dca2416a..14f2e01cc 100644 --- a/src/modules/list/tests/insert_line.rs +++ b/src/modules/list/tests/insert_line.rs @@ -6,7 +6,6 @@ fn insert_line() { testers::module( &[], &[Event::from(StandardEvent::InsertLine)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( diff --git a/src/modules/list/tests/movement.rs b/src/modules/list/tests/movement.rs index e059d7203..5c2feb3d8 100644 --- a/src/modules/list/tests/movement.rs +++ b/src/modules/list/tests/movement.rs @@ -10,7 +10,6 @@ fn move_down_1() { testers::module( &["pick aaa c1", "pick aaa c2", "pick aaa c3"], &[Event::from(StandardEvent::MoveCursorDown)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -30,7 +29,6 @@ fn move_down_view_end() { testers::module( &["pick aaa c1", "pick aaa c2", "pick aaa c3"], &[Event::from(StandardEvent::MoveCursorDown); 2], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -50,7 +48,6 @@ fn move_down_past_end() { testers::module( &["pick aaa c1", "pick aaa c2", "pick aaa c3"], &[Event::from(StandardEvent::MoveCursorDown); 3], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -74,7 +71,6 @@ fn move_down_scroll_bottom_move_up_one() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::MoveCursorUp), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -98,7 +94,6 @@ fn move_down_scroll_bottom_move_up_top() { Event::from(StandardEvent::MoveCursorUp), Event::from(StandardEvent::MoveCursorUp), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -121,7 +116,6 @@ fn move_up_attempt_above_top() { Event::from(StandardEvent::MoveCursorUp), Event::from(StandardEvent::MoveCursorUp), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -142,7 +136,6 @@ fn move_down_attempt_below_bottom() { testers::module( &["pick aaa c1", "pick aaa c2", "pick aaa c3", "pick aaa c4"], &[Event::from(StandardEvent::MoveCursorDown); 4], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -163,7 +156,6 @@ fn move_page_up_from_top() { testers::module( &["pick aaa c1", "pick aaa c2", "pick aaa c3", "pick aaa c4"], &[Event::from(StandardEvent::MoveCursorPageUp)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); module.height = 4; @@ -189,7 +181,6 @@ fn move_page_up_from_one_page_down() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::MoveCursorPageUp), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); module.height = 4; @@ -215,7 +206,6 @@ fn move_page_up_from_one_page_down_minus_1() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::MoveCursorPageUp), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); module.height = 4; @@ -242,7 +232,6 @@ fn move_page_up_from_bottom() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::MoveCursorPageUp), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); module.height = 4; @@ -268,7 +257,6 @@ fn move_home() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::MoveCursorHome), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -289,7 +277,6 @@ fn move_end() { testers::module( &["pick aaa c1", "pick aaa c2", "pick aaa c3", "pick aaa c4"], &[Event::from(StandardEvent::MoveCursorEnd)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -310,7 +297,6 @@ fn move_page_down_past_bottom() { testers::module( &["pick aaa c1", "pick aaa c2", "pick aaa c3", "pick aaa c4"], &[Event::from(StandardEvent::MoveCursorPageDown); 3], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); module.height = 4; @@ -337,7 +323,6 @@ fn move_page_down_one_from_bottom() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::MoveCursorPageDown), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -361,7 +346,6 @@ fn move_page_down_one_page_from_bottom() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::MoveCursorPageDown), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); module.height = 4; @@ -402,7 +386,6 @@ fn mouse_scroll() { modifiers: KeyModifiers::empty(), }), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -422,7 +405,6 @@ fn scroll_right() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::MoveCursorRight)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -436,7 +418,6 @@ fn scroll_left() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::MoveCursorLeft)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); diff --git a/src/modules/list/tests/normal_mode.rs b/src/modules/list/tests/normal_mode.rs index c4d236528..5e387d529 100644 --- a/src/modules/list/tests/normal_mode.rs +++ b/src/modules/list/tests/normal_mode.rs @@ -3,12 +3,12 @@ use crate::{action_line, assert_rendered_output, assert_results, input::KeyCode, #[test] fn change_auto_select_next_with_next_line() { - let mut config = create_config(); + let mut config = Config::default(); config.auto_select_next = true; - testers::module( + testers::module_with_config( &["pick aaa c1", "pick aaa c2"], &[Event::from(StandardEvent::ActionSquash)], - Some(config), + config, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -27,7 +27,6 @@ fn toggle_visual_mode() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::ToggleVisualMode)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( @@ -45,7 +44,6 @@ fn other_event() { testers::module( &["pick aaa c1"], &[Event::from(KeyCode::Null)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( diff --git a/src/modules/list/tests/read_event.rs b/src/modules/list/tests/read_event.rs index 3ca27b66c..efe3d745e 100644 --- a/src/modules/list/tests/read_event.rs +++ b/src/modules/list/tests/read_event.rs @@ -5,7 +5,7 @@ use crate::input::{KeyCode, KeyModifiers, MouseEvent}; #[test] fn edit_mode_passthrough_event() { - testers::read_event(Event::from('p'), None, |mut test_context| { + testers::read_event(Event::from('p'), |mut test_context| { let mut module = List::new(&test_context.app_data()); module.state = ListState::Edit; assert_eq!(test_context.read_event(&module), Event::from('p')); @@ -14,7 +14,7 @@ fn edit_mode_passthrough_event() { #[test] fn normal_mode_help() { - testers::read_event(Event::from('?'), None, |mut test_context| { + testers::read_event(Event::from('?'), |mut test_context| { let mut module = List::new(&test_context.app_data()); module.normal_mode_help.set_active(); assert_eq!(test_context.read_event(&module), Event::from(StandardEvent::Help)); @@ -23,7 +23,7 @@ fn normal_mode_help() { #[test] fn visual_mode_help() { - testers::read_event(Event::from('?'), None, |mut test_context| { + testers::read_event(Event::from('?'), |mut test_context| { let mut module = List::new(&test_context.app_data()); module.visual_mode_help.set_active(); assert_eq!(test_context.read_event(&module), Event::from(StandardEvent::Help)); @@ -32,7 +32,7 @@ fn visual_mode_help() { #[test] fn search() { - testers::read_event(Event::from('p'), None, |mut test_context| { + testers::read_event(Event::from('p'), |mut test_context| { let mut module = List::new(&test_context.app_data()); module.search_bar.start_search(Some("")); assert_eq!(test_context.read_event(&module), Event::from('p')); @@ -59,7 +59,7 @@ fn search() { #[case::showcommit('c', StandardEvent::ShowCommit)] #[case::togglevisualmode('v', StandardEvent::ToggleVisualMode)] fn default_events_single_char(#[case] binding: char, #[case] expected: StandardEvent) { - testers::read_event(Event::from(binding), None, |mut test_context| { + testers::read_event(Event::from(binding), |mut test_context| { let module = List::new(&test_context.app_data()); assert_eq!(test_context.read_event(&module), Event::from(expected)); }); @@ -76,7 +76,7 @@ fn default_events_single_char(#[case] binding: char, #[case] expected: StandardE #[case::movecursorpageup(KeyCode::PageUp, StandardEvent::MoveCursorPageUp)] #[case::delete(KeyCode::Delete, StandardEvent::Delete)] fn default_events_special(#[case] code: KeyCode, #[case] expected: StandardEvent) { - testers::read_event(Event::from(code), None, |mut test_context| { + testers::read_event(Event::from(code), |mut test_context| { let module = List::new(&test_context.app_data()); assert_eq!(test_context.read_event(&module), Event::from(expected)); }); @@ -87,7 +87,7 @@ fn default_events_special(#[case] code: KeyCode, #[case] expected: StandardEvent #[case::abort('U', StandardEvent::FixupKeepMessageWithEditor)] #[case::abort('p', StandardEvent::ActionPick)] fn fixup_events(#[case] binding: char, #[case] expected: StandardEvent) { - testers::read_event(Event::from(binding), None, |mut test_context| { + testers::read_event(Event::from(binding), |mut test_context| { let mut module = List::new(&test_context.app_data()); module.selected_line_action = Some(Action::Fixup); assert_eq!(test_context.read_event(&module), Event::from(expected)); @@ -98,7 +98,7 @@ fn fixup_events(#[case] binding: char, #[case] expected: StandardEvent) { #[case::abort('u')] #[case::abort('U')] fn fixup_events_with_non_fixpo_event(#[case] binding: char) { - testers::read_event(Event::from(binding), None, |mut test_context| { + testers::read_event(Event::from(binding), |mut test_context| { let mut module = List::new(&test_context.app_data()); module.selected_line_action = Some(Action::Pick); assert_eq!(test_context.read_event(&module), Event::from(binding)); @@ -114,7 +114,6 @@ fn mouse_move_down() { row: 0, modifiers: KeyModifiers::empty(), }), - None, |mut test_context| { let module = List::new(&test_context.app_data()); assert_eq!( @@ -134,7 +133,6 @@ fn mouse_move_up() { row: 0, modifiers: KeyModifiers::empty(), }), - None, |mut test_context| { let module = List::new(&test_context.app_data()); assert_eq!( @@ -153,7 +151,7 @@ fn mouse_other() { row: 0, modifiers: KeyModifiers::empty(), }); - testers::read_event(mouse_event, None, |mut test_context| { + testers::read_event(mouse_event, |mut test_context| { let module = List::new(&test_context.app_data()); assert_eq!(test_context.read_event(&module), mouse_event); }); @@ -161,7 +159,7 @@ fn mouse_other() { #[test] fn event_other() { - testers::read_event(Event::None, None, |mut test_context| { + testers::read_event(Event::None, |mut test_context| { let module = List::new(&test_context.app_data()); assert_eq!(test_context.read_event(&module), Event::None); }); diff --git a/src/modules/list/tests/remove_lines.rs b/src/modules/list/tests/remove_lines.rs index f5933b568..f8fba824b 100644 --- a/src/modules/list/tests/remove_lines.rs +++ b/src/modules/list/tests/remove_lines.rs @@ -12,7 +12,6 @@ fn normal_mode_remove_line_first() { "pick eee c5", ], &[Event::from(StandardEvent::Delete)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -44,7 +43,6 @@ fn normal_mode_remove_line_end() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::Delete), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -75,7 +73,6 @@ fn visual_mode_remove_lines_start_index_first() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::Delete), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -110,7 +107,6 @@ fn visual_mode_remove_lines_end_index_first() { Event::from(StandardEvent::MoveCursorUp), Event::from(StandardEvent::Delete), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -147,7 +143,6 @@ fn visual_mode_remove_lines_start_index_last() { Event::from(StandardEvent::MoveCursorUp), Event::from(StandardEvent::Delete), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -182,7 +177,6 @@ fn visual_mode_remove_lines_end_index_last() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::Delete), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); diff --git a/src/modules/list/tests/render.rs b/src/modules/list/tests/render.rs index 11ce6619a..107af4531 100644 --- a/src/modules/list/tests/render.rs +++ b/src/modules/list/tests/render.rs @@ -3,7 +3,7 @@ use crate::{assert_rendered_output, test_helpers::assertions::assert_rendered_ou #[test] fn empty_list() { - testers::module(&[], &[], None, |test_context| { + testers::module(&[], &[], |test_context| { let mut module = List::new(&test_context.app_data()); let view_data = test_context.build_view_data(&mut module); assert_rendered_output!( @@ -35,7 +35,6 @@ fn full() { "update-ref reference", ], &[], - None, |test_context| { let mut module = List::new(&test_context.app_data()); let view_data = test_context.build_view_data(&mut module); @@ -82,7 +81,6 @@ fn compact() { "update-ref reference", ], &[], - None, |mut test_context| { test_context.render_context.update(30, 300); let mut module = List::new(&test_context.app_data()); @@ -113,7 +111,7 @@ fn compact() { // this can technically never happen, but it's worth testing, just in case of an invalid state #[test] fn noop_list() { - testers::module(&["break"], &[], None, |test_context| { + testers::module(&["break"], &[], |test_context| { let mut module = List::new(&test_context.app_data()); let mut todo_file = module.todo_file.lock(); todo_file.remove_lines(0, 0); @@ -147,7 +145,6 @@ fn pinned_segments() { "merge command", ], &[Event::from(StandardEvent::ActionDrop)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -175,7 +172,7 @@ fn pinned_segments() { #[test] fn full_with_short_actions() { - testers::module(&["pick aaaaaaaa comment 1"], &[], None, |test_context| { + testers::module(&["pick aaaaaaaa comment 1"], &[], |test_context| { let mut module = List::new(&test_context.app_data()); let view_data = test_context.build_view_data(&mut module); assert_rendered_output!( diff --git a/src/modules/list/tests/search.rs b/src/modules/list/tests/search.rs index ff789ccd7..a2a6c7be7 100644 --- a/src/modules/list/tests/search.rs +++ b/src/modules/list/tests/search.rs @@ -11,7 +11,7 @@ use crate::{ modules::list::search::LineMatch, process::Artifact, search::Interrupter, - test_helpers::{assertions::AnyArtifact, create_test_keybindings, testers::ModuleTestContext}, + test_helpers::{assertions::AnyArtifact, testers::ModuleTestContext}, }; #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -47,13 +47,13 @@ impl TestContext { fn search_test(actions: &[Action<'_>], lines: &[&str], callback: C) where C: FnOnce(TestContext) { - testers::module(lines, &[], None, |test_context| { + testers::module(lines, &[], |test_context| { let module = List::new(&test_context.app_data()); let mut search_context = TestContext { module, module_test_context: test_context, results: vec![], - key_bindings: create_test_keybindings(), + key_bindings: KeyBindings::default(), }; let mut finish_pushed = false; diff --git a/src/modules/list/tests/show_commit.rs b/src/modules/list/tests/show_commit.rs index d5ca68d98..d4fa25dde 100644 --- a/src/modules/list/tests/show_commit.rs +++ b/src/modules/list/tests/show_commit.rs @@ -6,7 +6,6 @@ fn when_hash_available() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::ShowCommit)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( @@ -23,7 +22,6 @@ fn when_no_selected_line() { testers::module( &[], &[Event::from(StandardEvent::ShowCommit)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( @@ -39,7 +37,6 @@ fn do_not_when_hash_not_available() { testers::module( &["exec echo foo"], &[Event::from(StandardEvent::ShowCommit)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( diff --git a/src/modules/list/tests/swap_lines.rs b/src/modules/list/tests/swap_lines.rs index b864d4a76..d3d99761e 100644 --- a/src/modules/list/tests/swap_lines.rs +++ b/src/modules/list/tests/swap_lines.rs @@ -6,7 +6,6 @@ fn normal_mode_change_swap_down() { testers::module( &["pick aaa c1", "pick aaa c2", "pick aaa c3"], &[Event::from(StandardEvent::SwapSelectedDown)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -38,7 +37,6 @@ fn visual_mode_swap_down_from_top_to_bottom_selection() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::SwapSelectedDown), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -74,7 +72,6 @@ fn visual_mode_swap_down_from_bottom_to_top_selection() { Event::from(StandardEvent::MoveCursorUp), Event::from(StandardEvent::SwapSelectedDown), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -111,7 +108,6 @@ fn visual_mode_swap_down_to_limit_from_bottom_to_top_selection() { Event::from(StandardEvent::SwapSelectedDown), Event::from(StandardEvent::SwapSelectedDown), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -146,7 +142,6 @@ fn visual_mode_swap_down_to_limit_from_top_to_bottom_selection() { Event::from(StandardEvent::SwapSelectedDown), Event::from(StandardEvent::SwapSelectedDown), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -172,7 +167,6 @@ fn normal_mode_change_swap_up() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::SwapSelectedUp), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -204,7 +198,6 @@ fn visual_mode_swap_up_from_top_to_bottom_selection() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::SwapSelectedUp), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -240,7 +233,6 @@ fn visual_mode_swap_up_from_bottom_to_top_selection() { Event::from(StandardEvent::MoveCursorUp), Event::from(StandardEvent::SwapSelectedUp), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -275,7 +267,6 @@ fn visual_mode_swap_up_to_limit_from_top_to_bottom_selection() { Event::from(StandardEvent::SwapSelectedUp), Event::from(StandardEvent::SwapSelectedUp), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -312,7 +303,6 @@ fn visual_mode_swap_up_to_limit_from_bottom_to_top_selection() { Event::from(StandardEvent::SwapSelectedUp), Event::from(StandardEvent::SwapSelectedUp), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); diff --git a/src/modules/list/tests/toggle_break.rs b/src/modules/list/tests/toggle_break.rs index fdb3d14fa..761fea509 100644 --- a/src/modules/list/tests/toggle_break.rs +++ b/src/modules/list/tests/toggle_break.rs @@ -6,7 +6,6 @@ fn change_toggle_break_add() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::ActionBreak)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -28,7 +27,6 @@ fn change_toggle_break_remove() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::ActionBreak), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -46,7 +44,6 @@ fn change_toggle_break_above_existing() { testers::module( &["pick aaa c1", "break"], &[Event::from(StandardEvent::ActionBreak)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); diff --git a/src/modules/list/tests/toggle_option.rs b/src/modules/list/tests/toggle_option.rs index 1db361bf3..67f34d548 100644 --- a/src/modules/list/tests/toggle_option.rs +++ b/src/modules/list/tests/toggle_option.rs @@ -7,7 +7,6 @@ fn on_fixup_keep_message() { testers::module( &["fixup aaa c1"], &[Event::from(StandardEvent::FixupKeepMessage)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.activate(&mut module, State::List); @@ -24,7 +23,6 @@ fn on_fixup_keep_message_with_editor() { testers::module( &["fixup aaa c1"], &[Event::from(StandardEvent::FixupKeepMessageWithEditor)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.activate(&mut module, State::List); @@ -41,7 +39,6 @@ fn on_existing_option_remove_option() { testers::module( &["fixup -c aaa c1"], &[Event::from(StandardEvent::FixupKeepMessageWithEditor)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.activate(&mut module, State::List); @@ -58,7 +55,6 @@ fn after_select_line() { testers::module( &["fixup aaa c1", "fixup aaa c2", "fixup aaa c3"], &[Event::from(StandardEvent::MoveCursorDown), Event::from('u')], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.activate(&mut module, State::List); diff --git a/src/modules/list/tests/undo_redo.rs b/src/modules/list/tests/undo_redo.rs index ec9b5a2ed..e77d2b0b6 100644 --- a/src/modules/list/tests/undo_redo.rs +++ b/src/modules/list/tests/undo_redo.rs @@ -6,7 +6,6 @@ fn normal_mode_undo() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::ActionDrop), Event::from(StandardEvent::Undo)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_event(&mut module); @@ -34,7 +33,6 @@ fn normal_mode_undo_visual_mode_change() { Event::from(StandardEvent::ToggleVisualMode), Event::from(StandardEvent::Undo), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -57,7 +55,6 @@ fn normal_mode_redo() { Event::from(StandardEvent::Undo), Event::from(StandardEvent::Redo), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_event(&mut module); @@ -86,7 +83,6 @@ fn normal_mode_redo_visual_mode_change() { Event::from(StandardEvent::ToggleVisualMode), Event::from(StandardEvent::Redo), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -110,7 +106,6 @@ fn visual_mode_undo() { Event::from(StandardEvent::ActionDrop), Event::from(StandardEvent::Undo), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_n_events(&mut module, 3); @@ -137,7 +132,6 @@ fn visual_mode_undo_normal_mode_change() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::Undo), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_n_events(&mut module, 3); @@ -166,7 +160,6 @@ fn visual_mode_redo() { Event::from(StandardEvent::Undo), Event::from(StandardEvent::Redo), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -190,7 +183,6 @@ fn visual_mode_redo_normal_mode_change() { Event::from(StandardEvent::Undo), Event::from(StandardEvent::Redo), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); diff --git a/src/modules/list/tests/visual_mode.rs b/src/modules/list/tests/visual_mode.rs index 74529a597..2bfbaecb0 100644 --- a/src/modules/list/tests/visual_mode.rs +++ b/src/modules/list/tests/visual_mode.rs @@ -18,7 +18,6 @@ fn start() { testers::module( &["pick aaa c1", "pick aaa c2", "pick aaa c3"], &[Event::from(StandardEvent::ToggleVisualMode)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -41,7 +40,6 @@ fn start_cursor_down_one() { Event::from(StandardEvent::ToggleVisualMode), Event::from(StandardEvent::MoveCursorDown), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -70,7 +68,6 @@ fn start_cursor_page_down() { Event::from(StandardEvent::ToggleVisualMode), Event::from(StandardEvent::MoveCursorPageDown), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); module.height = 4; @@ -106,7 +103,6 @@ fn start_cursor_from_bottom_move_up() { Event::from(StandardEvent::ToggleVisualMode), Event::from(StandardEvent::MoveCursorUp), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -144,7 +140,6 @@ fn start_cursor_from_bottom_to_top() { Event::from(StandardEvent::MoveCursorUp), Event::from(StandardEvent::MoveCursorUp), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -171,7 +166,6 @@ fn action_change_top_bottom() { Event::from(StandardEvent::MoveCursorDown), Event::from(StandardEvent::ActionReword), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -198,7 +192,6 @@ fn action_change_bottom_top() { Event::from(StandardEvent::MoveCursorUp), Event::from(StandardEvent::ActionReword), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -221,7 +214,6 @@ fn toggle_visual_mode() { Event::from(StandardEvent::ToggleVisualMode), Event::from(StandardEvent::ToggleVisualMode), ], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); _ = test_context.handle_event(&mut module); @@ -240,7 +232,6 @@ fn other_event() { testers::module( &["pick aaa c1"], &[Event::from(KeyCode::Null)], - None, |mut test_context| { let mut module = List::new(&test_context.app_data()); assert_results!( diff --git a/src/modules/show_commit/tests.rs b/src/modules/show_commit/tests.rs index 79ea94f3b..1263a0976 100644 --- a/src/modules/show_commit/tests.rs +++ b/src/modules/show_commit/tests.rs @@ -6,6 +6,7 @@ use super::*; use crate::{ assert_rendered_output, assert_results, + config::Config, diff::{Commit, Delta, DiffLine, FileMode, Origin, Status, User}, input::StandardEvent, process::Artifact, @@ -13,7 +14,6 @@ use crate::{ test_helpers::{ assertions::assert_rendered_output::AssertRenderOptions, builders::{CommitBuilder, CommitDiffBuilder, FileStatusBuilder}, - create_config, testers, }, }; @@ -33,7 +33,7 @@ fn update_diff(module: &mut ShowCommit, builder: CommitDiffBuilder) { fn load_commit_during_activate() { let hash = "abcde12345"; let line = format!("pick {hash} comment1"); - testers::module(&[line.as_str()], &[], None, |test_context| { + testers::module(&[line.as_str()], &[], |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); assert_results!( test_context.activate(&mut module, State::List), @@ -46,7 +46,7 @@ fn load_commit_during_activate() { fn cached_commit_in_activate() { let hash = "abcde12345"; let line = format!("pick {hash} comment1"); - testers::module(&[line.as_str()], &[], None, |test_context| { + testers::module(&[line.as_str()], &[], |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); let diff = test_context.app_data().diff_state().diff(); // prefill cache @@ -62,7 +62,7 @@ fn cached_commit_in_activate() { #[test] fn no_selected_line_in_activate() { - testers::module(&[], &[], None, |test_context| { + testers::module(&[], &[], |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); assert_results!( test_context.activate(&mut module, State::List), @@ -79,7 +79,6 @@ fn render_cancelled_diff_race() { "pick abcdef0123456789abcdef0123456789 comment2", ], &[], - None, |test_context| { { let diff = test_context.app_data().diff_state().diff(); @@ -102,7 +101,6 @@ fn render_overview_minimal_commit() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let commit = CommitBuilder::new("0123456789abcdef0123456789abcdef").build(); let commit_date = commit.committed_date().format("%c %z").to_string(); @@ -130,7 +128,6 @@ fn render_overview_minimal_commit_compact() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |mut test_context| { test_context.render_context.update(30, 300); let commit = CommitBuilder::new("0123456789abcdef0123456789abcdef").build(); @@ -158,7 +155,6 @@ fn render_overview_with_author() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -185,7 +181,6 @@ fn render_overview_with_author_compact() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |mut test_context| { test_context.render_context.update(30, 300); let mut module = ShowCommit::new(&test_context.app_data()); @@ -213,7 +208,6 @@ fn render_overview_with_committer() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -240,7 +234,6 @@ fn render_overview_with_committer_compact() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |mut test_context| { test_context.render_context.update(30, 300); @@ -269,7 +262,6 @@ fn render_overview_with_commit_summary() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -296,7 +288,6 @@ fn render_overview_with_commit_body() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -323,7 +314,6 @@ fn render_overview_with_commit_summary_and_body() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -353,7 +343,6 @@ fn render_overview_with_file_stats() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -423,7 +412,6 @@ fn render_overview_with_file_stats_compact() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |mut test_context| { test_context.render_context.update(30, 300); @@ -494,7 +482,6 @@ fn render_overview_single_file_changed() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -519,7 +506,6 @@ fn render_overview_more_than_one_file_changed() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -545,7 +531,6 @@ fn render_overview_single_insertion() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -571,7 +556,6 @@ fn render_overview_more_than_one_insertion() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -597,7 +581,6 @@ fn render_overview_single_deletion() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -623,7 +606,6 @@ fn render_overview_more_than_one_deletion() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -646,12 +628,12 @@ fn render_overview_more_than_one_deletion() { #[test] fn render_diff_minimal_commit() { - let mut config = create_config(); + let mut config = Config::default(); config.diff_show_whitespace = DiffShowWhitespaceSetting::None; - testers::module( + testers::module_with_config( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - Some(config), + config, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -677,12 +659,12 @@ fn render_diff_minimal_commit() { #[test] fn render_diff_minimal_commit_compact() { - let mut config = create_config(); + let mut config = Config::default(); config.diff_show_whitespace = DiffShowWhitespaceSetting::None; - testers::module( + testers::module_with_config( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - Some(config), + config, |mut test_context| { test_context.render_context.update(30, 300); @@ -712,7 +694,6 @@ fn render_diff_basic_file_stats() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -788,12 +769,12 @@ fn render_diff_basic_file_stats() { #[test] fn render_diff_end_new_line_missing() { - let mut config = create_config(); + let mut config = Config::default(); config.diff_show_whitespace = DiffShowWhitespaceSetting::None; - testers::module( + testers::module_with_config( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - Some(config), + config, |test_context| { let mut delta = Delta::new("@@ -14,2 +13,3 @@ context", 14, 14, 0, 1); delta.add_line(DiffLine::new(Origin::Addition, "new line", None, Some(14), false)); @@ -836,12 +817,12 @@ fn render_diff_end_new_line_missing() { #[test] fn render_diff_add_line() { - let mut config = create_config(); + let mut config = Config::default(); config.diff_show_whitespace = DiffShowWhitespaceSetting::None; - testers::module( + testers::module_with_config( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - Some(config), + config, |test_context| { let mut delta = Delta::new("@@ -14,2 +13,3 @@ context", 14, 14, 0, 1); delta.add_line(DiffLine::new(Origin::Addition, "new line", None, Some(14), false)); @@ -882,12 +863,12 @@ fn render_diff_add_line() { #[test] fn render_diff_delete_line() { - let mut config = create_config(); + let mut config = Config::default(); config.diff_show_whitespace = DiffShowWhitespaceSetting::None; - testers::module( + testers::module_with_config( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - Some(config), + config, |test_context| { let mut delta = Delta::new("@@ -14,2 +13,3 @@ context", 14, 14, 0, 1); delta.add_line(DiffLine::new(Origin::Deletion, "old line", Some(14), None, false)); @@ -928,12 +909,12 @@ fn render_diff_delete_line() { #[test] fn render_diff_context_add_remove_lines() { - let mut config = create_config(); + let mut config = Config::default(); config.diff_show_whitespace = DiffShowWhitespaceSetting::None; - testers::module( + testers::module_with_config( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - Some(config), + config, |test_context| { let mut delta = Delta::new("@@ -14,2 +13,3 @@ context", 14, 14, 0, 1); delta.add_line(DiffLine::new(Origin::Context, "context 1", Some(13), Some(13), false)); @@ -1003,15 +984,15 @@ fn generate_white_space_delta() -> Delta { #[test] fn render_diff_show_both_whitespace() { - let mut config = create_config(); + let mut config = Config::default(); config.diff_show_whitespace = DiffShowWhitespaceSetting::Both; config.diff_tab_symbol = String::from("#>"); config.diff_space_symbol = String::from("%"); config.diff_tab_width = 2; - testers::module( + testers::module_with_config( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - Some(config), + config, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -1047,15 +1028,15 @@ fn render_diff_show_both_whitespace() { #[test] fn render_diff_show_leading_whitespace() { - let mut config = create_config(); + let mut config = Config::default(); config.diff_show_whitespace = DiffShowWhitespaceSetting::Leading; config.diff_tab_symbol = String::from("#>"); config.diff_space_symbol = String::from("%"); config.diff_tab_width = 2; - testers::module( + testers::module_with_config( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - Some(config), + config, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -1091,15 +1072,15 @@ fn render_diff_show_leading_whitespace() { #[test] fn render_diff_show_no_whitespace() { - let mut config = create_config(); + let mut config = Config::default(); config.diff_show_whitespace = DiffShowWhitespaceSetting::None; config.diff_tab_symbol = String::from("#>"); config.diff_space_symbol = String::from("%"); config.diff_tab_width = 2; - testers::module( + testers::module_with_config( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - Some(config), + config, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -1135,15 +1116,15 @@ fn render_diff_show_no_whitespace() { #[test] fn render_diff_show_whitespace_all_spaces() { - let mut config = create_config(); + let mut config = Config::default(); config.diff_show_whitespace = DiffShowWhitespaceSetting::Both; config.diff_tab_symbol = String::from("#>"); config.diff_space_symbol = String::from("%"); config.diff_tab_width = 2; - testers::module( + testers::module_with_config( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - Some(config), + config, |test_context| { let mut delta = Delta::new("@@ -1,7 +1,7 @@ context", 1, 1, 7, 7); delta.add_line(DiffLine::new(Origin::Addition, " ", None, Some(1), false)); @@ -1176,10 +1157,10 @@ fn render_diff_show_whitespace_all_spaces() { #[test] fn render_loading_new() { - testers::module( + testers::module_with_config( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, + Config::default(), |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -1204,7 +1185,6 @@ fn render_loading_quick_diff_progress() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -1232,7 +1212,6 @@ fn render_loading_quick_diff_complete() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -1260,7 +1239,6 @@ fn render_loading_diff_progress() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -1288,7 +1266,6 @@ fn render_loading_diff_error_not_found() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -1319,7 +1296,6 @@ fn render_loading_diff_error_other() { testers::module( &["pick 0123456789abcdef0123456789abcdef comment1"], &[], - None, |test_context| { let mut module = ShowCommit::new(&test_context.app_data()); update_diff( @@ -1350,7 +1326,6 @@ fn handle_event_toggle_diff_to_overview() { testers::module( &["pick 0123456789abcdef0123456789abcdef c1"], &[Event::from(StandardEvent::ShowDiff)], - None, |mut test_context| { let mut module = ShowCommit::new(&test_context.app_data()); module @@ -1371,7 +1346,6 @@ fn handle_event_toggle_overview_to_diff() { testers::module( &["pick 0123456789abcdef0123456789abcdef c1"], &[Event::from('d')], - None, |mut test_context| { let mut module = ShowCommit::new(&test_context.app_data()); module @@ -1392,7 +1366,6 @@ fn handle_event_resize() { testers::module( &["pick 0123456789abcdef0123456789abcdef c1"], &[Event::Resize(100, 100)], - None, |mut test_context| { let mut module = ShowCommit::new(&test_context.app_data()); assert_results!( @@ -1408,7 +1381,6 @@ fn render_help() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::Help)], - None, |mut test_context| { let mut module = ShowCommit::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -1434,7 +1406,6 @@ fn handle_help_event_show() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::Help)], - None, |mut test_context| { let mut module = ShowCommit::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -1447,7 +1418,6 @@ fn handle_help_event_hide() { testers::module( &["pick aaa c1"], &[Event::from(StandardEvent::Help), Event::from('?')], - None, |mut test_context| { let mut module = ShowCommit::new(&test_context.app_data()); _ = test_context.handle_all_events(&mut module); @@ -1461,7 +1431,6 @@ fn handle_event_other_key_from_diff() { testers::module( &["pick 0123456789abcdef0123456789abcdef c1"], &[Event::from('a')], - None, |mut test_context| { let mut module = ShowCommit::new(&test_context.app_data()); module.state = ShowCommitState::Diff; @@ -1479,7 +1448,6 @@ fn handle_event_other_key_from_overview() { testers::module( &["pick 0123456789abcdef0123456789abcdef c1"], &[Event::from('a')], - None, |mut test_context| { let mut module = ShowCommit::new(&test_context.app_data()); module.state = ShowCommitState::Overview; @@ -1501,7 +1469,7 @@ fn handle_event_other_key_from_overview() { #[case::scroll_jump_down(StandardEvent::ScrollJumpDown)] #[case::scroll_jump_up(StandardEvent::ScrollJumpUp)] fn scroll_events(#[case] event: StandardEvent) { - testers::module(&[], &[Event::from(event)], None, |mut test_context| { + testers::module_with_config(&[], &[Event::from(event)], Config::default(), |mut test_context| { let mut module = ShowCommit::new(&test_context.app_data()); assert_results!( test_context.handle_event(&mut module), diff --git a/src/modules/window_size_error.rs b/src/modules/window_size_error.rs index 01aab2215..41466c5e7 100644 --- a/src/modules/window_size_error.rs +++ b/src/modules/window_size_error.rs @@ -106,7 +106,7 @@ mod tests { "Window too small" )] fn build_view_data(#[case] width: usize, #[case] height: usize, #[case] expected: &str) { - testers::module(&[], &[], None, |mut test_context| { + testers::module(&[], &[], |mut test_context| { test_context.render_context.update(width as u16, height as u16); let mut module = WindowSizeError::new(); let view_data = test_context.build_view_data(&mut module); @@ -117,7 +117,7 @@ mod tests { #[test] fn event_resize_window_still_small() { - testers::module(&[], &[Event::Resize(1, 1)], None, |mut test_context| { + testers::module(&[], &[Event::Resize(1, 1)], |mut test_context| { let mut module = WindowSizeError::new(); _ = test_context.activate(&mut module, State::ConfirmRebase); assert_results!( @@ -129,7 +129,7 @@ mod tests { #[test] fn event_resize_window_no_longer_too_small() { - testers::module(&[], &[Event::Resize(100, 100)], None, |mut test_context| { + testers::module(&[], &[Event::Resize(100, 100)], |mut test_context| { let mut module = WindowSizeError::new(); _ = test_context.activate(&mut module, State::ConfirmRebase); assert_results!( @@ -142,7 +142,7 @@ mod tests { #[test] fn event_other_character() { - testers::module(&[], &[Event::from('a')], None, |mut test_context| { + testers::module(&[], &[Event::from('a')], |mut test_context| { let mut module = WindowSizeError::new(); _ = test_context.activate(&mut module, State::ConfirmRebase); assert_results!( diff --git a/src/test_helpers.rs b/src/test_helpers.rs index d51b10949..91abf3cf7 100644 --- a/src/test_helpers.rs +++ b/src/test_helpers.rs @@ -2,11 +2,9 @@ pub(crate) mod assertions; pub(crate) mod builders; mod create_commit; -mod create_config; mod create_default_test_module_handler; mod create_event_reader; mod create_invalid_utf; -mod create_test_keybindings; mod create_test_module_handler; pub(crate) mod mocks; mod shared; @@ -25,11 +23,9 @@ pub(crate) static JAN_2021_EPOCH: i64 = 1_609_459_200; pub(crate) use self::{ create_commit::{CreateCommitOptions, create_commit}, - create_config::create_config, create_default_test_module_handler::{DefaultTestModule, create_default_test_module_handler}, create_event_reader::create_event_reader, create_invalid_utf::invalid_utf, - create_test_keybindings::create_test_keybindings, create_test_module_handler::create_test_module_handler, shared::TestModuleProvider, with_env_var::{EnvVarAction, with_env_var}, diff --git a/src/test_helpers/create_config.rs b/src/test_helpers/create_config.rs deleted file mode 100644 index c4afd3825..000000000 --- a/src/test_helpers/create_config.rs +++ /dev/null @@ -1,5 +0,0 @@ -use crate::config::Config; - -pub(crate) fn create_config() -> Config { - Config::new_with_config(None).unwrap() -} diff --git a/src/test_helpers/create_default_test_module_handler.rs b/src/test_helpers/create_default_test_module_handler.rs index aabfaad1d..52e0274ff 100644 --- a/src/test_helpers/create_default_test_module_handler.rs +++ b/src/test_helpers/create_default_test_module_handler.rs @@ -1,7 +1,7 @@ use crate::{ - input::EventHandler, + input::{EventHandler, KeyBindings}, module::{Module, ModuleHandler}, - test_helpers::{TestModuleProvider, create_test_keybindings}, + test_helpers::TestModuleProvider, }; pub(crate) struct DefaultTestModule; @@ -10,7 +10,7 @@ impl Module for DefaultTestModule {} pub(crate) fn create_default_test_module_handler() -> ModuleHandler> { ModuleHandler::new( - EventHandler::new(create_test_keybindings()), + EventHandler::new(KeyBindings::default()), TestModuleProvider::::from(DefaultTestModule {}), ) } diff --git a/src/test_helpers/create_test_keybindings.rs b/src/test_helpers/create_test_keybindings.rs deleted file mode 100644 index b3b4b9ea1..000000000 --- a/src/test_helpers/create_test_keybindings.rs +++ /dev/null @@ -1,54 +0,0 @@ -use crate::input::{KeyBindings, map_keybindings}; - -/// Create a mocked version of `KeyBindings`. -#[must_use] -pub(crate) fn create_test_keybindings() -> KeyBindings { - KeyBindings { - redo: map_keybindings(&[String::from("Controly")]), - undo: map_keybindings(&[String::from("Controlz")]), - scroll_down: map_keybindings(&[String::from("Down")]), - scroll_end: map_keybindings(&[String::from("End")]), - scroll_home: map_keybindings(&[String::from("Home")]), - scroll_left: map_keybindings(&[String::from("Left")]), - scroll_right: map_keybindings(&[String::from("Right")]), - scroll_up: map_keybindings(&[String::from("Up")]), - scroll_step_down: map_keybindings(&[String::from("PageDown")]), - scroll_step_up: map_keybindings(&[String::from("PageUp")]), - help: map_keybindings(&[String::from("?")]), - search_start: map_keybindings(&[String::from("/")]), - search_next: map_keybindings(&[String::from("n")]), - search_previous: map_keybindings(&[String::from("N")]), - abort: map_keybindings(&[String::from("q")]), - action_break: map_keybindings(&[String::from("b")]), - action_drop: map_keybindings(&[String::from("d")]), - action_edit: map_keybindings(&[String::from("e")]), - action_fixup: map_keybindings(&[String::from("f")]), - action_pick: map_keybindings(&[String::from("p")]), - action_reword: map_keybindings(&[String::from("r")]), - action_squash: map_keybindings(&[String::from("s")]), - confirm_yes: map_keybindings(&[String::from("y")]), - edit: map_keybindings(&[String::from("E")]), - force_abort: map_keybindings(&[String::from("Q")]), - force_rebase: map_keybindings(&[String::from("W")]), - insert_line: map_keybindings(&[String::from("I")]), - duplicate_line: map_keybindings(&[String::from("ControlD")]), - move_down: map_keybindings(&[String::from("Down")]), - move_down_step: map_keybindings(&[String::from("PageDown")]), - move_end: map_keybindings(&[String::from("End")]), - move_home: map_keybindings(&[String::from("Home")]), - move_left: map_keybindings(&[String::from("Left")]), - move_right: map_keybindings(&[String::from("Right")]), - move_selection_down: map_keybindings(&[String::from("j")]), - move_selection_up: map_keybindings(&[String::from("k")]), - move_up: map_keybindings(&[String::from("Up")]), - move_up_step: map_keybindings(&[String::from("PageUp")]), - open_in_external_editor: map_keybindings(&[String::from('!')]), - rebase: map_keybindings(&[String::from('w')]), - remove_line: map_keybindings(&[String::from("Delete")]), - show_commit: map_keybindings(&[String::from("c")]), - show_diff: map_keybindings(&[String::from("d")]), - toggle_visual_mode: map_keybindings(&[String::from("v")]), - fixup_keep_message: map_keybindings(&[String::from("u")]), - fixup_keep_message_with_editor: map_keybindings(&[String::from("U")]), - } -} diff --git a/src/test_helpers/create_test_module_handler.rs b/src/test_helpers/create_test_module_handler.rs index b924dc5de..5194e2ea9 100644 --- a/src/test_helpers/create_test_module_handler.rs +++ b/src/test_helpers/create_test_module_handler.rs @@ -1,12 +1,12 @@ use crate::{ - input::EventHandler, + input::{EventHandler, KeyBindings}, module::{Module, ModuleHandler}, - test_helpers::{create_test_keybindings, shared::TestModuleProvider}, + test_helpers::shared::TestModuleProvider, }; pub(crate) fn create_test_module_handler(module: M) -> ModuleHandler> { ModuleHandler::new( - EventHandler::new(create_test_keybindings()), + EventHandler::new(KeyBindings::default()), TestModuleProvider::from(module), ) } diff --git a/src/test_helpers/testers.rs b/src/test_helpers/testers.rs index d07842465..c3eca5058 100644 --- a/src/test_helpers/testers.rs +++ b/src/test_helpers/testers.rs @@ -5,7 +5,7 @@ mod searchable; mod threadable; pub(crate) use self::{ - module::{ModuleTestContext, module_test as module}, + module::{ModuleTestContext, module_test as module, module_test_with_config as module_with_config}, process::{ProcessTestContext, process}, read_event::read_event, searchable::SearchableRunner, diff --git a/src/test_helpers/testers/module.rs b/src/test_helpers/testers/module.rs index 42a90710f..49b563d2d 100644 --- a/src/test_helpers/testers/module.rs +++ b/src/test_helpers/testers/module.rs @@ -14,7 +14,6 @@ use crate::{ test_helpers::{ EventHandlerTestContext, ViewStateTestContext, - create_config, with_event_handler, with_todo_file, with_view_state, @@ -84,7 +83,13 @@ impl ModuleTestContext { } } -pub(crate) fn module_test(lines: &[&str], events: &[Event], config: Option, callback: C) +pub(crate) fn module_test(lines: &[&str], events: &[Event], callback: C) +where C: FnOnce(ModuleTestContext) { + let config = Config::default(); + module_test_with_config(lines, events, config, callback) +} + +pub(crate) fn module_test_with_config(lines: &[&str], events: &[Event], config: Config, callback: C) where C: FnOnce(ModuleTestContext) { with_event_handler(events, |event_handler_context| { with_view_state(|view_context| { @@ -93,7 +98,7 @@ where C: FnOnce(ModuleTestContext) { let commit_diff = CommitDiff::new(); let (_git_todo_file, todo_file) = todo_file_context.to_owned(); let app_data = AppData::new( - config.unwrap_or_else(create_config), + config, State::WindowSizeError, Arc::new(Mutex::new(todo_file)), diff::thread::State::new(Arc::new(RwLock::new(commit_diff))), diff --git a/src/test_helpers/testers/process.rs b/src/test_helpers/testers/process.rs index 78e5788ba..3cc6514ac 100644 --- a/src/test_helpers/testers/process.rs +++ b/src/test_helpers/testers/process.rs @@ -4,6 +4,7 @@ use parking_lot::{Mutex, lock_api::RwLock}; use crate::{ application::AppData, + config::Config, diff, diff::CommitDiff, display::Size, @@ -13,7 +14,6 @@ use crate::{ runtime::ThreadStatuses, test_helpers::{ ViewStateTestContext, - create_config, with_event_handler, with_search, with_todo_file, @@ -42,7 +42,7 @@ pub(crate) fn process(event: Event, config: Option, callback: C) +pub(crate) fn read_event(event: Event, callback: C) where C: FnOnce(testers::ModuleTestContext) { - testers::module(&[], &[event], config, callback); + testers::module(&[], &[event], callback); } diff --git a/src/test_helpers/with_event_handler.rs b/src/test_helpers/with_event_handler.rs index f3ab500e3..8c71028c3 100644 --- a/src/test_helpers/with_event_handler.rs +++ b/src/test_helpers/with_event_handler.rs @@ -1,6 +1,5 @@ use crate::{ - input::{Event, EventHandler, State}, - test_helpers::create_test_keybindings, + input::{Event, EventHandler, KeyBindings, State}, }; /// Context for a `EventHandler` based test. @@ -18,7 +17,7 @@ pub(crate) struct EventHandlerTestContext { /// Provide an `EventHandler` instance for use within a test. pub(crate) fn with_event_handler(events: &[Event], callback: C) where C: FnOnce(EventHandlerTestContext) { - let event_handler = EventHandler::new(create_test_keybindings()); + let event_handler = EventHandler::new(KeyBindings::default()); let state = State::new(); for event in events { diff --git a/src/view/tests.rs b/src/view/tests.rs index 6d1263003..530c15992 100644 --- a/src/view/tests.rs +++ b/src/view/tests.rs @@ -2,7 +2,7 @@ use super::*; use crate::{config::Theme, display::Size, test_helpers::mocks}; fn assert_render_slice(width: usize, height: usize, render_slice: &RenderSlice, expected: &[&str]) { - let theme = Theme::new_with_config(None).unwrap(); + let theme = Theme::default(); let mut crossterm = mocks::CrossTerm::new(); let readonly_tui = crossterm.clone(); crossterm.set_size(Size::new(width, height)); diff --git a/src/view/thread.rs b/src/view/thread.rs index cd78d1ea9..5f8013914 100644 --- a/src/view/thread.rs +++ b/src/view/thread.rs @@ -176,7 +176,7 @@ mod tests { fn with_view(tui: CT, callback: C) where C: FnOnce(View) { - let theme = Theme::new_with_config(None).unwrap(); + let theme = Theme::default(); let display = Display::new(tui, &theme); callback(View::new(display, "~", "?")); }