keymap: Test backslash escaping in commands

pull/5185/head
ds-cbo 2 years ago committed by Michael Davis
parent 91dca3f667
commit 67a287dd81
No known key found for this signature in database

@ -448,9 +448,16 @@ impl MappableCommand {
impl fmt::Debug for MappableCommand { impl fmt::Debug for MappableCommand {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("MappableCommand") match self {
.field(&self.name()) MappableCommand::Static { name, .. } => {
.finish() f.debug_tuple("MappableCommand").field(name).finish()
}
MappableCommand::Typable { name, args, .. } => f
.debug_tuple("MappableCommand")
.field(name)
.field(args)
.finish(),
}
} }
} }
@ -505,12 +512,16 @@ impl PartialEq for MappableCommand {
match (self, other) { match (self, other) {
( (
MappableCommand::Typable { MappableCommand::Typable {
name: first_name, .. name: first_name,
args: first_args,
..
}, },
MappableCommand::Typable { MappableCommand::Typable {
name: second_name, .. name: second_name,
args: second_args,
..
}, },
) => first_name == second_name, ) => first_name == second_name && first_args == second_args,
( (
MappableCommand::Static { MappableCommand::Static {
name: first_name, .. name: first_name, ..

@ -600,4 +600,43 @@ mod tests {
"Mismatch" "Mismatch"
) )
} }
#[test]
fn escaped_keymap() {
use crate::commands::MappableCommand;
use helix_view::input::{KeyCode, KeyEvent, KeyModifiers};
let keys = r#"
"+" = [
"select_all",
":pipe sed -E 's/\\s+$//g'",
]
"#;
let key = KeyEvent {
code: KeyCode::Char('+'),
modifiers: KeyModifiers::NONE,
};
let expectation = Keymap::new(KeyTrie::Node(KeyTrieNode::new(
"",
hashmap! {
key => KeyTrie::Sequence(vec!{
MappableCommand::select_all,
MappableCommand::Typable {
name: "pipe".to_string(),
args: vec!{
"sed".to_string(),
"-E".to_string(),
"'s/\\s+$//g'".to_string()
},
doc: "".to_string(),
},
})
},
vec![key],
)));
assert_eq!(toml::from_str(keys), Ok(expectation));
}
} }

Loading…
Cancel
Save