Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue parsing after a c0 code in the middle of a stream #13

Merged
merged 1 commit into from
Jun 13, 2016
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 src/ControlCodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function handleData($data)
$this->buffer = (string)substr($this->buffer, 1);

$this->emit('c0', array($data));
break;
continue;
}

// check following byte to determine type
Expand Down
8 changes: 8 additions & 0 deletions tests/ControlCodeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ public function testEmitsDataAndC0()
$this->input->emit('data', array("hello world\n"));
}

public function testEmitsC0AndData()
{
$this->parser->on('data', $this->expectCallableOnceWith("hello world"));
$this->parser->on('c0', $this->expectCallableOnceWith("\t"));

$this->input->emit('data', array("\thello world"));
}

public function testEmitsCsiAndData()
{
$this->parser->on('data', $this->expectCallableOnceWith("hello"));
Expand Down
31 changes: 31 additions & 0 deletions tests/FunctionalControlCodeParserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use React\EventLoop\Factory;
use React\Stream\Stream;
use Clue\React\Term\ControlCodeParser;

class FunctionalControlCodeParserTest extends TestCase
{
public function testPipingReadme()
{
$loop = Factory::create();

$input = new Stream(fopen(__DIR__ . '/../README.md', 'r'), $loop);
$parser = new ControlCodeParser($input);

$buffer = '';
$parser->on('data', function ($chunk) use (&$buffer) {
$buffer .= $chunk;
});

$loop->run();

$readme = str_replace(
"\n",
'',
file_get_contents(__DIR__ . '/../README.md')
);

$this->assertEquals($readme, $buffer);
}
}