Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react/event-loop": "0.3.*|0.4.*",
"react/stream": "^0.4.2",
"clue/utf8-react": "^0.1",
"clue/term-react": "^0.1"
"clue/term-react": "^0.1.1"
},
"autoload": {
"psr-4": { "Clue\\React\\Stdio\\": "src/" }
Expand Down
2 changes: 0 additions & 2 deletions src/Stdin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class Stdin extends Stream
public function __construct(LoopInterface $loop)
{
parent::__construct(STDIN, $loop);

$this->bufferSize = 1;
}

public function resume()
Expand Down
40 changes: 22 additions & 18 deletions tests/ReadlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,36 +195,47 @@ public function testDataEventWillBeEmittedForCompleteLine()
{
$this->readline->on('data', $this->expectCallableOnceWith('hello'));

$this->pushInputBytes($this->readline, "hello\n");
$this->input->emit('data', array("hello\n"));
}

public function testDataEventWillNotBeEmittedForIncompleteLine()
public function testDataEventWillNotBeEmittedForIncompleteLineButWillStayInInputBuffer()
{
$this->readline->on('data', $this->expectCallableNever());

$this->pushInputBytes($this->readline, "hello");
$this->input->emit('data', array("hello"));

$this->assertEquals('hello', $this->readline->getInput());
}

public function testDataEventWillBeEmittedForCompleteLineAndRemainingWillStayInInputBuffer()
{
$this->readline->on('data', $this->expectCallableOnceWith('hello'));

$this->input->emit('data', array("hello\nworld"));

$this->assertEquals('world', $this->readline->getInput());
}

public function testDataEventWillBeEmittedForEmptyLine()
{
$this->readline->on('data', $this->expectCallableOnceWith(''));

$this->pushInputBytes($this->readline, "\n");
$this->input->emit('data', array("\n"));
}

public function testWriteSimpleCharWritesOnce()
{
$this->output->expects($this->once())->method('write')->with($this->equalTo("\r\033[K" . "k"));

$this->pushInputBytes($this->readline, 'k');
$this->input->emit('data', array('k'));
}

public function testWriteMultiByteCharWritesOnce()
{
$this->output->expects($this->once())->method('write')->with($this->equalTo("\r\033[K" . "\xF0\x9D\x84\x9E"));

// "𝄞" – U+1D11E MUSICAL SYMBOL G CLEF
$this->pushInputBytes($this->readline, "\xF0\x9D\x84\x9E");
$this->input->emit('data', array("\xF0\x9D\x84\x9E"));
}

public function testKeysHomeMovesToFront()
Expand Down Expand Up @@ -276,7 +287,7 @@ public function testKeysRightMovesToRight(Readline $readline)

public function testKeysSimpleChars()
{
$this->pushInputBytes($this->readline, 'hi!');
$this->input->emit('data', array('hi!'));

$this->assertEquals('hi!', $this->readline->getInput());
$this->assertEquals(3, $this->readline->getCursorPosition());
Expand All @@ -300,7 +311,7 @@ public function testKeysBackspaceDeletesLastCharacter(Readline $readline)

public function testKeysMultiByteInput()
{
$this->pushInputBytes($this->readline, 'hä');
$this->input->emit('data', array('hä'));

$this->assertEquals('hä', $this->readline->getInput());
$this->assertEquals(2, $this->readline->getCursorPosition());
Expand Down Expand Up @@ -372,7 +383,7 @@ public function testKeysPrependCharacterInFrontOfMultiByte()
$this->readline->setInput('ü');
$this->readline->moveCursorTo(0);

$this->pushInputBytes($this->readline, 'h');
$this->input->emit('data', array('h'));

$this->assertEquals('hü', $this->readline->getInput());
$this->assertEquals(1, $this->readline->getCursorPosition());
Expand All @@ -383,7 +394,7 @@ public function testKeysWriteMultiByteAfterMultiByte()
{
$this->readline->setInput('ü');

$this->pushInputBytes($this->readline, 'ä');
$this->input->emit('data', array('ä'));

$this->assertEquals('üä', $this->readline->getInput());
$this->assertEquals(2, $this->readline->getCursorPosition());
Expand All @@ -395,7 +406,7 @@ public function testKeysPrependMultiByteInFrontOfMultiByte()
$this->readline->setInput('ü');
$this->readline->moveCursorTo(0);

$this->pushInputBytes($this->readline, 'ä');
$this->input->emit('data', array('ä'));

$this->assertEquals('äü', $this->readline->getInput());
$this->assertEquals(1, $this->readline->getCursorPosition());
Expand Down Expand Up @@ -579,11 +590,4 @@ public function testPipeWillReturnDest()

$this->assertEquals($dest, $ret);
}

private function pushInputBytes(Readline $readline, $bytes)
{
foreach (str_split($bytes, 1) as $byte) {
$this->input->emit('data', array($byte));
}
}
}