@@ -476,7 +476,11 @@ fn complete_cmdname(
476476) -> Vec < String > {
477477 // Complete command name and set cursor position.
478478 let _ = text. get_prefix_word_mut ( cursor, & WordStyle :: Little ) ;
479- store. cmds . complete_name ( desc. command . as_str ( ) )
479+ let mut comps = store. cmds . complete_name ( desc. command . as_str ( ) ) ;
480+
481+ comps. extend ( store. cmds . complete_aliases ( desc. command . as_str ( ) ) ) ;
482+
483+ comps
480484}
481485
482486/// Tab completion for commands.
@@ -582,7 +586,12 @@ impl Completer<IambInfo> for IambCompleter {
582586#[ cfg( test) ]
583587pub mod tests {
584588 use super :: * ;
585- use crate :: tests:: * ;
589+ use crate :: {
590+ base:: { ProgramCommand , ProgramCommands } ,
591+ commands:: add_iamb_commands,
592+ tests:: * ,
593+ } ;
594+ use modalkit:: { commands:: CommandResult , env:: vim:: command:: CommandContext } ;
586595 use pretty_assertions:: assert_eq;
587596
588597 #[ tokio:: test]
@@ -613,6 +622,7 @@ pub mod tests {
613622 async fn test_complete_cmdbar ( ) {
614623 let store = mock_store ( ) . await ;
615624 let store = store. application ;
625+ let cmds = vec ! [ "accept" , "reject" , "send" ] ;
616626 let users = vec ! [
617627 "@user1:example.com" ,
618628 "@user2:example.com" ,
@@ -632,20 +642,20 @@ pub mod tests {
632642 let text = EditRope :: from ( "invite " ) ;
633643 let mut cursor = Cursor :: new ( 0 , 7 ) ;
634644 let res = complete_cmdbar ( & text, & mut cursor, & store) ;
635- assert_eq ! ( res, users ) ;
645+ assert_eq ! ( res, cmds ) ;
636646
637647 let text = EditRope :: from ( "invite ignored" ) ;
638648 let mut cursor = Cursor :: new ( 0 , 7 ) ;
639649 let res = complete_cmdbar ( & text, & mut cursor, & store) ;
640- assert_eq ! ( res, users ) ;
650+ assert_eq ! ( res, cmds ) ;
641651
642- let text = EditRope :: from ( "invite @user1ignored" ) ;
643- let mut cursor = Cursor :: new ( 0 , 13 ) ;
652+ let text = EditRope :: from ( "invite send @user1ignored" ) ;
653+ let mut cursor = Cursor :: new ( 0 , 18 ) ;
644654 let res = complete_cmdbar ( & text, & mut cursor, & store) ;
645655 assert_eq ! ( res, vec![ "@user1:example.com" ] ) ;
646656
647- let text = EditRope :: from ( "abo hor " ) ;
648- let mut cursor = Cursor :: new ( 0 , 7 ) ;
657+ let text = EditRope :: from ( "abo hori " ) ;
658+ let mut cursor = Cursor :: new ( 0 , 8 ) ;
649659 let res = complete_cmdbar ( & text, & mut cursor, & store) ;
650660 assert_eq ! ( res, vec![ "horizontal" ] ) ;
651661
@@ -654,13 +664,59 @@ pub mod tests {
654664 let res = complete_cmdbar ( & text, & mut cursor, & store) ;
655665 assert_eq ! ( res, vec![ "invite" ] ) ;
656666
657- let text = EditRope :: from ( "abo hor invite \n " ) ;
658- let mut cursor = Cursor :: new ( 0 , 15 ) ;
667+ let text = EditRope :: from ( "abo hor invite send \n " ) ;
668+ let mut cursor = Cursor :: new ( 0 , 20 ) ;
659669 let res = complete_cmdbar ( & text, & mut cursor, & store) ;
660670 assert_eq ! ( res, users) ;
661671 }
662672
663- fn test_all_commands_complete ( ) {
664- todo ! ( )
673+ #[ tokio:: test]
674+ async fn test_all_commands_complete ( ) {
675+ let mut cmds = ProgramCommands :: new ( ) ;
676+ add_iamb_commands ( & mut cmds) ;
677+
678+ let store = mock_store ( ) . await ;
679+ let mut store = store. application ;
680+ store. cmds = cmds;
681+ let cmds = & store. cmds ;
682+
683+ for command in cmds. complete_name ( "" ) {
684+ let mut text = EditRope :: from ( command) ;
685+ text += " " . into ( ) ;
686+ let mut cursor = text. last ( ) ;
687+ cursor. right ( 1 ) ;
688+ complete_cmdbar ( & text, & mut cursor, & store) ;
689+ }
690+ }
691+
692+ fn mock_command (
693+ _: CommandDescription ,
694+ _: & mut CommandContext ,
695+ ) -> CommandResult < ProgramCommand > {
696+ panic ! ( "mock command called" ) ;
697+ }
698+
699+ #[ tokio:: test]
700+ #[ should_panic( expected = "trying to complete unknown subcommand `testmockcommand`" ) ]
701+ async fn test_complete_unknown_panics ( ) {
702+ let mut cmds = ProgramCommands :: new ( ) ;
703+ cmds. add_command ( ProgramCommand {
704+ name : "testmockcommand" . into ( ) ,
705+ aliases : vec ! [ ] ,
706+ f : mock_command,
707+ } ) ;
708+
709+ let store = mock_store ( ) . await ;
710+ let mut store = store. application ;
711+ store. cmds = cmds;
712+ let cmds = & store. cmds ;
713+
714+ for command in cmds. complete_name ( "" ) {
715+ let mut text = EditRope :: from ( command) ;
716+ text += " " . into ( ) ;
717+ let mut cursor = text. last ( ) ;
718+ cursor. right ( 1 ) ;
719+ complete_cmdbar ( & text, & mut cursor, & store) ;
720+ }
665721 }
666722}
0 commit comments