diff --git a/src/Lexer.php b/src/Lexer.php index 82c357b..f63ee68 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -36,7 +36,7 @@ class Lexer public function __construct($string) { $this->string = $string; - $this->currentCharacter = $string{0}; + $this->currentCharacter = ($string !== '') ? $string{0} : null; $this->characterPosition = 0; } diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 51354ec..6be8ce5 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -5,6 +5,37 @@ class ParserTest extends TestCase { + /** + * @test + */ + public function shouldParseEmptyCode() + { + $parser = new Parser(''); + + $this->assertEquals( + [], + $parser->parse() + ); + } + + /** + * @test + */ + public function shouldParseBlankCode() + { + $parser = new Parser(' '); + + $this->assertEquals( + [ + [ + 'type' => 'text', + 'payload' => ' ' + ] + ], + $parser->parse() + ); + } + /** * @test */