Skip to content

Commit

Permalink
Merge pull request #9 from mficzel/task/avoidErrorsForEmptyAfxCode
Browse files Browse the repository at this point in the history
TASK: Avoid errors if an empty string is parsed
  • Loading branch information
mficzel authored May 30, 2017
2 parents 930e052 + 92d4c1b commit 391c83c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
31 changes: 31 additions & 0 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 391c83c

Please sign in to comment.