Skip to content

Commit

Permalink
Adds a unit-test to ensure that every Action has a default keybinding
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeHalasy committed Oct 8, 2023
1 parent ad6e296 commit 9f74a7f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use serde::{
de::{self, Visitor},
Deserialize,
};
use strum::{EnumIter, IntoEnumIterator};

pub static CONFIG: OnceLock<Config> = OnceLock::new();
#[macro_export]
Expand Down Expand Up @@ -202,7 +203,7 @@ impl<'de> Deserialize<'de> for Keymaps {
}
}

#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
#[derive(Deserialize, Clone, Debug, PartialEq, Eq, EnumIter)]
#[serde(rename_all(deserialize = "snake_case"))]
pub enum Action {
MoveDown,
Expand Down Expand Up @@ -342,6 +343,20 @@ mod tests {
use super::*;
use crossterm::style::Color;

#[test]
fn every_action_has_a_default_key() {
let mut action_list: Vec<Action> = Action::iter().collect();
for (_, action) in Keymaps::default().navigation {
action_list.retain(|x| x != &action);
}

assert!(
action_list.is_empty(),
"The following Actions do not have a default keybinding: {:?}",
action_list
)
}

// Should be up to date with the example config in the README.
#[test]
fn parse_readme_example() {
Expand Down

0 comments on commit 9f74a7f

Please sign in to comment.