@@ -839,4 +839,67 @@ public function testHistoryLimitUnlimitedDoesNotTruncate()
839839
840840 $ this ->assertCount (1000 , $ this ->readline ->listHistory ());
841841 }
842+
843+ public function testHistoryLimitRestoresOriginalInputIfCurrentIsTruncated ()
844+ {
845+ $ this ->readline ->addHistory ('a ' );
846+ $ this ->readline ->addHistory ('b ' );
847+
848+ $ this ->readline ->setInput ('hello ' );
849+
850+ $ this ->readline ->onKeyUp ();
851+
852+ $ this ->readline ->limitHistory (0 );
853+
854+ $ this ->assertEquals ('hello ' , $ this ->readline ->getInput ());
855+ }
856+
857+ public function testHistoryLimitKeepsCurrentIfCurrentRemainsDespiteTruncation ()
858+ {
859+ $ this ->readline ->addHistory ('a ' );
860+ $ this ->readline ->addHistory ('b ' );
861+
862+ $ this ->readline ->onKeyUp ();
863+
864+ $ this ->readline ->limitHistory (1 );
865+
866+ $ this ->assertEquals ('b ' , $ this ->readline ->getInput ());
867+ }
868+
869+ public function testHistoryLimitOnlyInBetweenTruncatesToLastAndKeepsInput ()
870+ {
871+ $ this ->readline ->addHistory ('a ' );
872+ $ this ->readline ->addHistory ('b ' );
873+
874+ $ this ->readline ->onKeyUp ();
875+
876+ $ this ->readline ->limitHistory (3 );
877+
878+ $ this ->assertEquals ('b ' , $ this ->readline ->getInput ());
879+
880+ $ this ->readline ->addHistory ('c ' );
881+ $ this ->readline ->addHistory ('d ' );
882+
883+ $ this ->assertCount (3 , $ this ->readline ->listHistory ());
884+ $ this ->assertEquals (array ('b ' , 'c ' , 'd ' ), $ this ->readline ->listHistory ());
885+
886+ $ this ->assertEquals ('b ' , $ this ->readline ->getInput ());
887+ }
888+
889+ public function testHistoryLimitRestoresOriginalIfCurrentIsTruncatedDueToAdding ()
890+ {
891+ $ this ->readline ->addHistory ('a ' );
892+ $ this ->readline ->addHistory ('b ' );
893+
894+ $ this ->readline ->setInput ('hello ' );
895+
896+ $ this ->readline ->onKeyUp ();
897+
898+ $ this ->readline ->limitHistory (1 );
899+
900+ $ this ->readline ->addHistory ('c ' );
901+ $ this ->readline ->addHistory ('d ' );
902+
903+ $ this ->assertEquals ('hello ' , $ this ->readline ->getInput ());
904+ }
842905}
0 commit comments