on master help sign in
keymap: Test backslash escaping in commands
commit67a287dd818bea14d550951a9660e8b0775bd8d0 authords-cbo <82801887+ds-cbo@users.noreply.github.com> dateFri 16 Dec 2022, 15:53 (4 years ago) parent91dca3f
2 files changed+56−6
helix-term/src/commands.rs+17−6 helix-term/src/keymap.rs+39
helix-term/src/commands.rs+17−6
@@ -448,9 +448,16 @@ impl MappableCommand {
448448
449449impl fmt::Debug for MappableCommand {
450450 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
451− f.debug_tuple("MappableCommand")
452− .field(&self.name())
453− .finish()
451+ match self {
452+ MappableCommand::Static { name, .. } => {
453+ f.debug_tuple("MappableCommand").field(name).finish()
454+ }
455+ MappableCommand::Typable { name, args, .. } => f
456+ .debug_tuple("MappableCommand")
457+ .field(name)
458+ .field(args)
459+ .finish(),
460+ }
454461 }
455462}
456463
@@ -505,12 +512,16 @@ impl PartialEq for MappableCommand {
505512 match (self, other) {
506513 (
507514 MappableCommand::Typable {
508− name: first_name, ..
515+ name: first_name,
516+ args: first_args,
517+ ..
509518 },
510519 MappableCommand::Typable {
511− name: second_name, ..
520+ name: second_name,
521+ args: second_args,
522+ ..
512523 },
513− ) => first_name == second_name,
524+ ) => first_name == second_name && first_args == second_args,
514525 (
515526 MappableCommand::Static {
516527 name: first_name, ..
helix-term/src/keymap.rs+39
@@ -600,4 +600,43 @@ mod tests {
600600 "Mismatch"
601601 )
602602 }
603+
604+ #[test]
605+ fn escaped_keymap() {
606+ use crate::commands::MappableCommand;
607+ use helix_view::input::{KeyCode, KeyEvent, KeyModifiers};
608+
609+ let keys = r#"
610+"+" = [
611+ "select_all",
612+ ":pipe sed -E 's/\\s+$//g'",
613+]
614+ "#;
615+
616+ let key = KeyEvent {
617+ code: KeyCode::Char('+'),
618+ modifiers: KeyModifiers::NONE,
619+ };
620+
621+ let expectation = Keymap::new(KeyTrie::Node(KeyTrieNode::new(
622+ "",
623+ hashmap! {
624+ key => KeyTrie::Sequence(vec!{
625+ MappableCommand::select_all,
626+ MappableCommand::Typable {
627+ name: "pipe".to_string(),
628+ args: vec!{
629+ "sed".to_string(),
630+ "-E".to_string(),
631+ "'s/\\s+$//g'".to_string()
632+ },
633+ doc: "".to_string(),
634+ },
635+ })
636+ },
637+ vec![key],
638+ )));
639+
640+ assert_eq!(toml::from_str(keys), Ok(expectation));
641+ }
603642}