Skip to content

Commit

Permalink
Making the parser stateless
Browse files Browse the repository at this point in the history
  • Loading branch information
mamazu committed Jan 24, 2022
1 parent d7827c7 commit d7f637c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public function parse(string $value, int $flags = 0)
if (null !== $mbEncoding) {
mb_internal_encoding($mbEncoding);
}
$this->refsBeingParsed = [];
$this->offset = 0;
$this->lines = [];
$this->currentLine = '';
$this->refs = [];
Expand Down
14 changes: 14 additions & 0 deletions Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ public function invalidIndentation(): array
];
}

public function testParserIsStateless()
{
$yamlString = '# translations/messages.en.yaml
';
$this->parser->parse($yamlString);
$this->parser->parse($yamlString);

$this->expectException(ParseException::class);
$this->expectExceptionMessage("A YAML file cannot contain tabs as indentation at line 2 (near \"\tabc\")");

$this->parser->parse("abc:\n\tabc");
}

/**
* @dataProvider validTokenSeparators
*/
Expand Down

0 comments on commit d7f637c

Please sign in to comment.