Move test to test module

pull/924/head
Nehliin 3 years ago committed by Blaž Hrastnik
parent fbba47fbc0
commit f133d80e70

@ -654,63 +654,67 @@ pub fn merge_keys(mut config: Config) -> Config {
config config
} }
#[test] #[cfg(test)]
fn merge_partial_keys() { mod tests {
let config = Config { use super::*;
keys: Keymaps(hashmap! { #[test]
Mode::Normal => Keymap::new( fn merge_partial_keys() {
keymap!({ "Normal mode" let config = Config {
"i" => normal_mode, keys: Keymaps(hashmap! {
"无" => insert_mode, Mode::Normal => Keymap::new(
"z" => jump_backward, keymap!({ "Normal mode"
"g" => { "Merge into goto mode" "i" => normal_mode,
"$" => goto_line_end, "无" => insert_mode,
"g" => delete_char_forward, "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); ..Default::default()
};
let keymap = merged_config.keys.0.get_mut(&Mode::Normal).unwrap(); let mut merged_config = merge_keys(config.clone());
assert_eq!( assert_ne!(config, merged_config);
keymap.get(key!('i')).kind,
KeymapResultKind::Matched(Command::normal_mode), let keymap = merged_config.keys.0.get_mut(&Mode::Normal).unwrap();
"Leaf should replace leaf" assert_eq!(
); keymap.get(key!('i')).kind,
assert_eq!( KeymapResultKind::Matched(Command::normal_mode),
keymap.get(key!('无')).kind, "Leaf should replace leaf"
KeymapResultKind::Matched(Command::insert_mode), );
"New leaf should be present in merged keymap" assert_eq!(
); keymap.get(key!('无')).kind,
// Assumes that z is a node in the default keymap KeymapResultKind::Matched(Command::insert_mode),
assert_eq!( "New leaf should be present in merged keymap"
keymap.get(key!('z')).kind, );
KeymapResultKind::Matched(Command::jump_backward), // Assumes that z is a node in the default keymap
"Leaf should replace node" assert_eq!(
); keymap.get(key!('z')).kind,
// Assumes that `g` is a node in default keymap KeymapResultKind::Matched(Command::jump_backward),
assert_eq!( "Leaf should replace node"
keymap.root().search(&[key!('g'), key!('$')]).unwrap(), );
&KeyTrie::Leaf(Command::goto_line_end), // Assumes that `g` is a node in default keymap
"Leaf should be present in merged subnode" assert_eq!(
); keymap.root().search(&[key!('g'), key!('$')]).unwrap(),
// Assumes that `gg` is in default keymap &KeyTrie::Leaf(Command::goto_line_end),
assert_eq!( "Leaf should be present in merged subnode"
keymap.root().search(&[key!('g'), key!('g')]).unwrap(), );
&KeyTrie::Leaf(Command::delete_char_forward), // Assumes that `gg` is in default keymap
"Leaf should replace old leaf in merged subnode" assert_eq!(
); keymap.root().search(&[key!('g'), key!('g')]).unwrap(),
// Assumes that `ge` is in default keymap &KeyTrie::Leaf(Command::delete_char_forward),
assert_eq!( "Leaf should replace old leaf in merged subnode"
keymap.root().search(&[key!('g'), key!('e')]).unwrap(), );
&KeyTrie::Leaf(Command::goto_last_line), // Assumes that `ge` is in default keymap
"Old leaves in subnode should be present in merged node" assert_eq!(
); keymap.root().search(&[key!('g'), key!('e')]).unwrap(),
&KeyTrie::Leaf(Command::goto_last_line),
assert!(merged_config.keys.0.get(&Mode::Normal).unwrap().len() > 1); "Old leaves in subnode should be present in merged node"
assert!(merged_config.keys.0.get(&Mode::Insert).unwrap().len() > 0); );
assert!(merged_config.keys.0.get(&Mode::Normal).unwrap().len() > 1);
assert!(merged_config.keys.0.get(&Mode::Insert).unwrap().len() > 0);
}
} }

Loading…
Cancel
Save