aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorGokul Soumya2021-11-10 06:15:32 +0000
committerBlaž Hrastnik2021-11-10 15:58:25 +0000
commitf9e9efb3ecc4aa22c270c043f7442791e810940c (patch)
tree299882e8f5994e12daa72daba23a6d2c82297e31 /helix-term
parent80036b8bd3f7815b3256aae20a17b31efc104fbd (diff)
Check for duplicate keys in default keymap
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/keymap.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index b41c950b..53e0d450 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -64,10 +64,11 @@ macro_rules! keymap {
$(
$(
let _key = $key.parse::<::helix_view::input::KeyEvent>().unwrap();
- _map.insert(
+ let _duplicate = _map.insert(
_key,
keymap!(@trie $value)
);
+ debug_assert!(_duplicate.is_none(), "Duplicate key found: {:?}", _duplicate.unwrap());
_order.push(_key);
)+
)*
@@ -691,6 +692,22 @@ pub fn merge_keys(mut config: Config) -> Config {
#[cfg(test)]
mod tests {
use super::*;
+
+ #[test]
+ #[should_panic]
+ fn duplicate_keys_should_panic() {
+ keymap!({ "Normal mode"
+ "i" => normal_mode,
+ "i" => goto_definition,
+ });
+ }
+
+ #[test]
+ fn check_duplicate_keys_in_default_keymap() {
+ // will panic on duplicate keys, assumes that `Keymaps` uses keymap! macro
+ Keymaps::default();
+ }
+
#[test]
fn merge_partial_keys() {
let config = Config {