File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed
Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ class MemoryHistory implements History
88{
99 private $ lines = array ();
1010 private $ position = null ;
11+ private $ unsaved = null ;
1112
1213 public function addLine ($ line )
1314 {
@@ -29,8 +30,7 @@ public function moveUp(Readline $readline)
2930 if ($ this ->position === null ) {
3031 // first time up => move to last entry
3132 $ this ->position = count ($ this ->lines ) - 1 ;
32-
33- // TODO: buffer current user input
33+ $ this ->unsaved = $ readline ->getInput ();
3434 } else {
3535 // somewhere in the list => move by one
3636 $ this ->position --;
@@ -50,8 +50,8 @@ public function moveDown(Readline $readline)
5050 $ this ->position ++;
5151 $ readline ->setInput ($ this ->lines [$ this ->position ]);
5252 } else {
53- // moved beyond bottom => restore empty input
54- $ readline ->setInput ('' );
53+ // moved beyond bottom => restore original unsaved input
54+ $ readline ->setInput ($ this -> unsaved );
5555 $ this ->position = null ;
5656 }
5757 }
Original file line number Diff line number Diff line change @@ -74,4 +74,28 @@ public function testMovingInEmptyHistoryDoesNothing()
7474 $ this ->history ->moveUp ($ this ->readline );
7575 $ this ->history ->moveDown ($ this ->readline );
7676 }
77+
78+ public function testMovingUpClearsCurrentInput ()
79+ {
80+ $ this ->readline ->expects ($ this ->once ())->method ('getInput ' )->will ($ this ->returnValue ('input ' ));
81+
82+ $ this ->history ->addLine ('first ' );
83+
84+ $ this ->readline ->expects ($ this ->once ())->method ('setInput ' )->with ($ this ->equalTo ('first ' ));
85+
86+ $ this ->history ->moveUp ($ this ->readline );
87+
88+ return $ this ->history ;
89+ }
90+
91+ /**
92+ * @depends testMovingUpClearsCurrentInput
93+ * @param History $history
94+ */
95+ public function testMovingDownRestoresLastBufferAgain (History $ history )
96+ {
97+ $ this ->readline ->expects ($ this ->once ())->method ('setInput ' )->with ($ this ->equalTo ('input ' ));
98+
99+ $ history ->moveDown ($ this ->readline );
100+ }
77101}
You can’t perform that action at this time.
0 commit comments