@@ -573,15 +573,15 @@ public function testAutocompleteWillBeCalledWithLastWordPrefix()
573573 $ this ->readline ->onKeyTab ();
574574 }
575575
576- public function testAutocompletePicksFirstWhenEmpty ()
576+ public function testAutocompleteAddsSpaceAfterComplete ()
577577 {
578- $ this ->markTestIncomplete ( );
578+ $ this ->readline -> setAutocomplete ( function () { return array ( ' exit ' ); } );
579579
580- $ this ->readline ->setAutocomplete ( function () { return array ( ' first ' , ' second ' ); } );
580+ $ this ->readline ->setInput ( ' exit ' );
581581
582582 $ this ->readline ->onKeyTab ();
583583
584- $ this ->assertEquals ('first ' , $ this ->readline ->getInput ());
584+ $ this ->assertEquals ('exit ' , $ this ->readline ->getInput ());
585585 }
586586
587587 public function testAutocompletePicksFirstComplete ()
@@ -606,6 +606,51 @@ public function testAutocompleteIgnoresNonMatching()
606606 $ this ->assertEquals ('e ' , $ this ->readline ->getInput ());
607607 }
608608
609+ public function testAutocompletePicksNoneWhenEmptyAndMultipleMatch ()
610+ {
611+ $ this ->readline ->setAutocomplete (function () { return array ('first ' , 'second ' ); });
612+
613+ $ this ->readline ->onKeyTab ();
614+
615+ $ this ->assertEquals ('' , $ this ->readline ->getInput ());
616+ }
617+
618+ public function testAutocompletePicksOnlyEntryWhenEmpty ()
619+ {
620+ $ this ->readline ->setAutocomplete (function () { return array ('first ' ); });
621+
622+ $ this ->readline ->onKeyTab ();
623+
624+ $ this ->assertEquals ('first ' , $ this ->readline ->getInput ());
625+ }
626+
627+ public function testAutocompleteUsesCommonPrefixWhenMultipleMatch ()
628+ {
629+ $ this ->readline ->setAutocomplete (function () { return array ('first ' , 'firm ' ); });
630+
631+ $ this ->readline ->onKeyTab ();
632+
633+ $ this ->assertEquals ('fir ' , $ this ->readline ->getInput ());
634+ }
635+
636+ public function testAutocompleteUsesExactMatchWhenDuplicateMatch ()
637+ {
638+ $ this ->readline ->setAutocomplete (function () { return array ('first ' , 'first ' ); });
639+
640+ $ this ->readline ->onKeyTab ();
641+
642+ $ this ->assertEquals ('first ' , $ this ->readline ->getInput ());
643+ }
644+
645+ public function testAutocompleteUsesCommonPrefixWhenMultipleMatchAndEnd ()
646+ {
647+ $ this ->readline ->setAutocomplete (function () { return array ('counter ' , 'count ' ); });
648+
649+ $ this ->readline ->onKeyTab ();
650+
651+ $ this ->assertEquals ('count ' , $ this ->readline ->getInput ());
652+ }
653+
609654 public function testEmitEmptyInputOnEnter ()
610655 {
611656 $ this ->readline ->on ('data ' , $ this ->expectCallableOnceWith ('' ));
0 commit comments