From cde3a4cc79e376ebd861edaea173fd9401dcbf21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 13 Jun 2016 20:04:44 +0200 Subject: [PATCH] Continue parsing after a c0 code in the middle of a stream --- src/ControlCodeParser.php | 2 +- tests/ControlCodeParserTest.php | 8 ++++++ tests/FunctionalControlCodeParserTest.php | 31 +++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/FunctionalControlCodeParserTest.php diff --git a/src/ControlCodeParser.php b/src/ControlCodeParser.php index 788e472..1721591 100644 --- a/src/ControlCodeParser.php +++ b/src/ControlCodeParser.php @@ -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 diff --git a/tests/ControlCodeParserTest.php b/tests/ControlCodeParserTest.php index dcd998a..c48cf5f 100644 --- a/tests/ControlCodeParserTest.php +++ b/tests/ControlCodeParserTest.php @@ -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")); diff --git a/tests/FunctionalControlCodeParserTest.php b/tests/FunctionalControlCodeParserTest.php new file mode 100644 index 0000000..83ed67c --- /dev/null +++ b/tests/FunctionalControlCodeParserTest.php @@ -0,0 +1,31 @@ +on('data', function ($chunk) use (&$buffer) { + $buffer .= $chunk; + }); + + $loop->run(); + + $readme = str_replace( + "\n", + '', + file_get_contents(__DIR__ . '/../README.md') + ); + + $this->assertEquals($readme, $buffer); + } +}