diff options
author | ds-cbo | 2022-12-16 14:53:37 +0000 |
---|---|---|
committer | Michael Davis | 2023-01-25 15:31:58 +0000 |
commit | 67a287dd818bea14d550951a9660e8b0775bd8d0 (patch) | |
tree | a538845ed5e208f77c276b10e514325ca176d3ed /helix-term | |
parent | 91dca3f667e146f93e6dca205b0a3f2a7a64b488 (diff) |
keymap: Test backslash escaping in commands
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 23 | ||||
-rw-r--r-- | helix-term/src/keymap.rs | 39 |
2 files changed, 56 insertions, 6 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index e7091401..365d5b65 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -448,9 +448,16 @@ impl MappableCommand { impl fmt::Debug for MappableCommand { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_tuple("MappableCommand") - .field(&self.name()) - .finish() + match self { + MappableCommand::Static { name, .. } => { + 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) { ( MappableCommand::Typable { - name: first_name, .. + name: first_name, + args: first_args, + .. }, 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 { name: first_name, .. diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index 416dcd86..e94a5f66 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -600,4 +600,43 @@ mod tests { "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)); + } } |