on master help sign in
Check for duplicate keys in default keymap
commitf9e9efb3ecc4aa22c270c043f7442791e810940c authorGokul Soumya <gokulps15@gmail.com> dateWed 10 Nov 2021, 11:45 (5 years ago) parent80036b8
1 file changed+18−1
helix-term/src/keymap.rs+18−1
helix-term/src/keymap.rs+18−1
@@ -64,10 +64,11 @@ macro_rules! keymap {
6464 $(
6565 $(
6666 let _key = $key.parse::<::helix_view::input::KeyEvent>().unwrap();
67− _map.insert(
67+ let _duplicate = _map.insert(
6868 _key,
6969 keymap!(@trie $value)
7070 );
71+ debug_assert!(_duplicate.is_none(), "Duplicate key found: {:?}", _duplicate.unwrap());
7172 _order.push(_key);
7273 )+
7374 )*
@@ -691,6 +692,22 @@ pub fn merge_keys(mut config: Config) -> Config {
691692#[cfg(test)]
692693mod tests {
693694 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+
694711 #[test]
695712 fn merge_partial_keys() {
696713 let config = Config {