Skip to content

Commit b741435

Browse files
authored
Merge pull request #13 from clue-labs/continue
Continue parsing after a c0 code in the middle of a stream
2 parents 8d0bdef + cde3a4c commit b741435

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/ControlCodeParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function handleData($data)
131131
$this->buffer = (string)substr($this->buffer, 1);
132132

133133
$this->emit('c0', array($data));
134-
break;
134+
continue;
135135
}
136136

137137
// check following byte to determine type

tests/ControlCodeParserTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ public function testEmitsDataAndC0()
8787
$this->input->emit('data', array("hello world\n"));
8888
}
8989

90+
public function testEmitsC0AndData()
91+
{
92+
$this->parser->on('data', $this->expectCallableOnceWith("hello world"));
93+
$this->parser->on('c0', $this->expectCallableOnceWith("\t"));
94+
95+
$this->input->emit('data', array("\thello world"));
96+
}
97+
9098
public function testEmitsCsiAndData()
9199
{
92100
$this->parser->on('data', $this->expectCallableOnceWith("hello"));
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use React\EventLoop\Factory;
4+
use React\Stream\Stream;
5+
use Clue\React\Term\ControlCodeParser;
6+
7+
class FunctionalControlCodeParserTest extends TestCase
8+
{
9+
public function testPipingReadme()
10+
{
11+
$loop = Factory::create();
12+
13+
$input = new Stream(fopen(__DIR__ . '/../README.md', 'r'), $loop);
14+
$parser = new ControlCodeParser($input);
15+
16+
$buffer = '';
17+
$parser->on('data', function ($chunk) use (&$buffer) {
18+
$buffer .= $chunk;
19+
});
20+
21+
$loop->run();
22+
23+
$readme = str_replace(
24+
"\n",
25+
'',
26+
file_get_contents(__DIR__ . '/../README.md')
27+
);
28+
29+
$this->assertEquals($readme, $buffer);
30+
}
31+
}

0 commit comments

Comments
 (0)