|
| 1 | +<?php |
| 2 | + |
| 3 | +use Clue\React\Stdio\Readline\WordAutocomplete; |
| 4 | + |
| 5 | +class WordAutocompleteTest extends TestCase |
| 6 | +{ |
| 7 | + private $readline; |
| 8 | + |
| 9 | + public function setUp() |
| 10 | + { |
| 11 | + $this->readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock(); |
| 12 | + } |
| 13 | + |
| 14 | + public function testWordEndDoesCompleteCorrectWordAndAppendsTrailingSpaceAndMovesCursor() |
| 15 | + { |
| 16 | + $autocomplete = new WordAutocomplete(array('first', 'second')); |
| 17 | + |
| 18 | + $this->readline->expects($this->once())->method('getInput')->will($this->returnValue('fir')); |
| 19 | + $this->readline->expects($this->once())->method('getCursorPosition')->will($this->returnValue(3)); |
| 20 | + |
| 21 | + $this->readline->expects($this->once())->method('setInput')->with($this->equalTo('first ')); |
| 22 | + $this->readline->expects($this->once())->method('moveCursorTo')->with($this->equalTo(6)); |
| 23 | + |
| 24 | + $autocomplete->go($this->readline); |
| 25 | + } |
| 26 | + |
| 27 | + public function testCursorInMiddleOfWordDoesCompleteCorrectWordAndMovesCursorBehindCompleted() |
| 28 | + { |
| 29 | + $autocomplete = new WordAutocomplete(array('first', 'second')); |
| 30 | + |
| 31 | + $this->readline->expects($this->once())->method('getInput')->will($this->returnValue('fir')); |
| 32 | + $this->readline->expects($this->once())->method('getCursorPosition')->will($this->returnValue(2)); |
| 33 | + |
| 34 | + $this->readline->expects($this->once())->method('setInput')->with($this->equalTo('firstr')); |
| 35 | + $this->readline->expects($this->once())->method('moveCursorTo')->with($this->equalTo(5)); |
| 36 | + |
| 37 | + $autocomplete->go($this->readline); |
| 38 | + } |
| 39 | + |
| 40 | + public function testUnknownInputWillNotBeCompleted() |
| 41 | + { |
| 42 | + $autocomplete = new WordAutocomplete(array('first', 'second')); |
| 43 | + |
| 44 | + $this->readline->expects($this->once())->method('getInput')->will($this->returnValue('test')); |
| 45 | + $this->readline->expects($this->never())->method('setInput'); |
| 46 | + |
| 47 | + $autocomplete->go($this->readline); |
| 48 | + } |
| 49 | + |
| 50 | + public function testEmptyInputWillNotBeCompleted() |
| 51 | + { |
| 52 | + $autocomplete = new WordAutocomplete(array('first', 'second')); |
| 53 | + |
| 54 | + $this->readline->expects($this->once())->method('getInput')->will($this->returnValue('')); |
| 55 | + $this->readline->expects($this->never())->method('setInput'); |
| 56 | + |
| 57 | + $autocomplete->go($this->readline); |
| 58 | + } |
| 59 | + |
| 60 | + public function testWordInSentenceDoesCompleteSentence() |
| 61 | + { |
| 62 | + $autocomplete = new WordAutocomplete(array('first', 'second')); |
| 63 | + |
| 64 | + $this->readline->expects($this->once())->method('getInput')->will($this->returnValue('hello fir')); |
| 65 | + $this->readline->expects($this->once())->method('getCursorPosition')->will($this->returnValue(9)); |
| 66 | + |
| 67 | + $this->readline->expects($this->once())->method('setInput')->with($this->equalTo('hello first ')); |
| 68 | + $this->readline->expects($this->once())->method('moveCursorTo')->with($this->equalTo(12)); |
| 69 | + |
| 70 | + $autocomplete->go($this->readline); |
| 71 | + } |
| 72 | +} |
0 commit comments