on master help sign in
Check for duplicate keys in default keymap
f9e9efbGokul Soumya
helix-term/src/keymap.rs+18−1
@@ -64,10 +64,11 @@ macro_rules! keymap {
64 $(
64 $(
65 $(
65 $(
66 let _key = $key.parse::<::helix_view::input::KeyEvent>().unwrap();
66 let _key = $key.parse::<::helix_view::input::KeyEvent>().unwrap();
67− _map.insert(
67+ let _duplicate = _map.insert(
68 _key,
68 _key,
69 keymap!(@trie $value)
69 keymap!(@trie $value)
70 );
70 );
71+ debug_assert!(_duplicate.is_none(), "Duplicate key found: {:?}", _duplicate.unwrap());
71 _order.push(_key);
72 _order.push(_key);
72 )+
73 )+
73 )*
74 )*
@@ -691,6 +692,22 @@ pub fn merge_keys(mut config: Config) -> Config {
691#[cfg(test)]
692#[cfg(test)]
692mod tests {
693mod tests {
693 use super::*;
694 use super::*;
695+
696+ #[test]
697+ #[should_panic]
698+ fn duplicate_keys_should_panic() {
699+ keymap!({ "Normal mode"
700+ "i" => normal_mode,
701+ "i" => goto_definition,
702+ });
703+ }
704+
705+ #[test]
706+ fn check_duplicate_keys_in_default_keymap() {
707+ // will panic on duplicate keys, assumes that `Keymaps` uses keymap! macro
708+ Keymaps::default();
709+ }
710+
694 #[test]
711 #[test]
695 fn merge_partial_keys() {
712 fn merge_partial_keys() {
696 let config = Config {
713 let config = Config {