diff --git a/composer.json b/composer.json index e9b4c7c..928386e 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "php": "^7.4 || ^8.0", "ext-mbstring": "*", "cypresslab/php-curry": "^0.5.0", - "mallardduck/immutable-read-file": "^0.5.2" + "mallardduck/immutable-read-file": "^0.5.3" }, "require-dev": { "ext-json": "*", @@ -56,7 +56,7 @@ }, "autoload-dev": { "psr-4": { - "Tests\\Verraes\\Parsica\\": "tests/" + "Tests\\Parsica\\Parsica\\": "tests/" } }, "scripts": { diff --git a/src/PHPUnit/ParserAssertions.php b/src/PHPUnit/ParserAssertions.php index fae0ec8..19e1af4 100644 --- a/src/PHPUnit/ParserAssertions.php +++ b/src/PHPUnit/ParserAssertions.php @@ -12,6 +12,7 @@ use Exception; use Parsica\Parsica\Parser; +use Parsica\Parsica\Stream; use Parsica\Parsica\StringStream; /** @@ -46,6 +47,29 @@ protected function assertParses(string $input, Parser $parser, $expectedOutput, } } + /** + * @psalm-param mixed $expectedOutput + * + * @api + */ + protected function assertParsesStream(Stream $input, Parser $parser, $expectedOutput, string $message = ""): void + { + $actualResult = $parser->run($input); + if ($actualResult->isSuccess()) { + $this->assertStrictlyEquals( + $expectedOutput, + $actualResult->output(), + $message . "\n" . "The parser succeeded but the output doesn't match your expected output." + ); + } else { + $this->fail( + $message . "\n" + ."The parser failed with the following error message:\n" + .$actualResult->errorMessage()."\n" + ); + } + } + /** * Behaves like assertSame for primitives, behaves like assertEquals for objects of the same type, and fails * for everything else. diff --git a/src/TextFileStream.php b/src/TextFileStream.php index 586161c..720e838 100644 --- a/src/TextFileStream.php +++ b/src/TextFileStream.php @@ -1,12 +1,12 @@