diff options
author | Nehliin | 2021-10-16 13:22:36 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-10-28 01:22:52 +0000 |
commit | f133d80e70622b9cf8b882473453aca02208024d (patch) | |
tree | 88ea167d17049dec0429dcf9afbf89f3ccc80ff7 /helix-term/src | |
parent | fbba47fbc09d26cc41db87c5477dd7d27e8f6787 (diff) |
Move test to test module
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/keymap.rs | 122 |
1 files changed, 63 insertions, 59 deletions
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index c7b8e895..b91fa055 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -654,63 +654,67 @@ pub fn merge_keys(mut config: Config) -> Config { config } -#[test] -fn merge_partial_keys() { - let config = Config { - keys: Keymaps(hashmap! { - Mode::Normal => Keymap::new( - keymap!({ "Normal mode" - "i" => normal_mode, - "无" => insert_mode, - "z" => jump_backward, - "g" => { "Merge into goto mode" - "$" => goto_line_end, - "g" => delete_char_forward, - }, - }) - ) - }), - ..Default::default() - }; - let mut merged_config = merge_keys(config.clone()); - assert_ne!(config, merged_config); - - let keymap = merged_config.keys.0.get_mut(&Mode::Normal).unwrap(); - assert_eq!( - keymap.get(key!('i')).kind, - KeymapResultKind::Matched(Command::normal_mode), - "Leaf should replace leaf" - ); - assert_eq!( - keymap.get(key!('无')).kind, - KeymapResultKind::Matched(Command::insert_mode), - "New leaf should be present in merged keymap" - ); - // Assumes that z is a node in the default keymap - assert_eq!( - keymap.get(key!('z')).kind, - KeymapResultKind::Matched(Command::jump_backward), - "Leaf should replace node" - ); - // Assumes that `g` is a node in default keymap - assert_eq!( - keymap.root().search(&[key!('g'), key!('$')]).unwrap(), - &KeyTrie::Leaf(Command::goto_line_end), - "Leaf should be present in merged subnode" - ); - // Assumes that `gg` is in default keymap - assert_eq!( - keymap.root().search(&[key!('g'), key!('g')]).unwrap(), - &KeyTrie::Leaf(Command::delete_char_forward), - "Leaf should replace old leaf in merged subnode" - ); - // Assumes that `ge` is in default keymap - assert_eq!( - keymap.root().search(&[key!('g'), key!('e')]).unwrap(), - &KeyTrie::Leaf(Command::goto_last_line), - "Old leaves in subnode should be present in merged node" - ); - - assert!(merged_config.keys.0.get(&Mode::Normal).unwrap().len() > 1); - assert!(merged_config.keys.0.get(&Mode::Insert).unwrap().len() > 0); +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn merge_partial_keys() { + let config = Config { + keys: Keymaps(hashmap! { + Mode::Normal => Keymap::new( + keymap!({ "Normal mode" + "i" => normal_mode, + "无" => insert_mode, + "z" => jump_backward, + "g" => { "Merge into goto mode" + "$" => goto_line_end, + "g" => delete_char_forward, + }, + }) + ) + }), + ..Default::default() + }; + let mut merged_config = merge_keys(config.clone()); + assert_ne!(config, merged_config); + + let keymap = merged_config.keys.0.get_mut(&Mode::Normal).unwrap(); + assert_eq!( + keymap.get(key!('i')).kind, + KeymapResultKind::Matched(Command::normal_mode), + "Leaf should replace leaf" + ); + assert_eq!( + keymap.get(key!('无')).kind, + KeymapResultKind::Matched(Command::insert_mode), + "New leaf should be present in merged keymap" + ); + // Assumes that z is a node in the default keymap + assert_eq!( + keymap.get(key!('z')).kind, + KeymapResultKind::Matched(Command::jump_backward), + "Leaf should replace node" + ); + // Assumes that `g` is a node in default keymap + assert_eq!( + keymap.root().search(&[key!('g'), key!('$')]).unwrap(), + &KeyTrie::Leaf(Command::goto_line_end), + "Leaf should be present in merged subnode" + ); + // Assumes that `gg` is in default keymap + assert_eq!( + keymap.root().search(&[key!('g'), key!('g')]).unwrap(), + &KeyTrie::Leaf(Command::delete_char_forward), + "Leaf should replace old leaf in merged subnode" + ); + // Assumes that `ge` is in default keymap + assert_eq!( + keymap.root().search(&[key!('g'), key!('e')]).unwrap(), + &KeyTrie::Leaf(Command::goto_last_line), + "Old leaves in subnode should be present in merged node" + ); + + assert!(merged_config.keys.0.get(&Mode::Normal).unwrap().len() > 1); + assert!(merged_config.keys.0.get(&Mode::Insert).unwrap().len() > 0); + } } |