@@ -777,4 +777,66 @@ public function testHistoryClearWhileCyclingRestoresOriginalInput()
777777
778778 $ this ->assertEquals ('hello ' , $ this ->readline ->getInput ());
779779 }
780+
781+ public function testHistoryLimitReturnsSelf ()
782+ {
783+ $ this ->assertSame ($ this ->readline , $ this ->readline ->limitHistory (100 ));
784+ }
785+
786+ public function testHistoryLimitTruncatesCurrentListToLimit ()
787+ {
788+ $ this ->readline ->addHistory ('a ' );
789+ $ this ->readline ->addHistory ('b ' );
790+ $ this ->readline ->addHistory ('c ' );
791+
792+ $ this ->readline ->limitHistory (2 );
793+
794+ $ this ->assertCount (2 , $ this ->readline ->listHistory ());
795+ $ this ->assertEquals (array ('b ' , 'c ' ), $ this ->readline ->listHistory ());
796+ }
797+
798+ public function testHistoryLimitToZeroEmptiesCurrentList ()
799+ {
800+ $ this ->readline ->addHistory ('a ' );
801+ $ this ->readline ->addHistory ('b ' );
802+ $ this ->readline ->addHistory ('c ' );
803+
804+ $ this ->readline ->limitHistory (0 );
805+
806+ $ this ->assertCount (0 , $ this ->readline ->listHistory ());
807+ }
808+
809+ public function testHistoryLimitTruncatesAddingBeyondLimit ()
810+ {
811+ $ this ->readline ->limitHistory (2 );
812+
813+ $ this ->readline ->addHistory ('a ' );
814+ $ this ->readline ->addHistory ('b ' );
815+ $ this ->readline ->addHistory ('c ' );
816+
817+ $ this ->assertCount (2 , $ this ->readline ->listHistory ());
818+ $ this ->assertEquals (array ('b ' , 'c ' ), $ this ->readline ->listHistory ());
819+ }
820+
821+ public function testHistoryLimitZeroAlwaysReturnsEmpty ()
822+ {
823+ $ this ->readline ->limitHistory (0 );
824+
825+ $ this ->readline ->addHistory ('a ' );
826+ $ this ->readline ->addHistory ('b ' );
827+ $ this ->readline ->addHistory ('c ' );
828+
829+ $ this ->assertCount (0 , $ this ->readline ->listHistory ());
830+ }
831+
832+ public function testHistoryLimitUnlimitedDoesNotTruncate ()
833+ {
834+ $ this ->readline ->limitHistory (null );
835+
836+ for ($ i = 0 ; $ i < 1000 ; ++$ i ) {
837+ $ this ->readline ->addHistory ('line ' . $ i );
838+ }
839+
840+ $ this ->assertCount (1000 , $ this ->readline ->listHistory ());
841+ }
780842}
0 commit comments