From c6801426167f99f1ea3da8730f27877b594da055 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Tue, 15 Sep 2020 22:44:16 +0200 Subject: Tests: Test parsing invalid input >95% coverage of the parser, hooray! --- tests/unit/ParserTest.php | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'tests') diff --git a/tests/unit/ParserTest.php b/tests/unit/ParserTest.php index 0a5ccb8..1e41ad0 100644 --- a/tests/unit/ParserTest.php +++ b/tests/unit/ParserTest.php @@ -8,6 +8,7 @@ use kch42\ste\Parser; use kch42\ste\TextNode; use kch42\ste\VariableNode; use kch42\ste\TagNode; +use kch42\ste\ParseCompileError; class ParserTest extends TestCase { @@ -173,4 +174,84 @@ class ParserTest extends TestCase ]], ]; } + + /** + * @dataProvider failsToParseDataProvider + * @param string $input + */ + public function testFailsToParse(string $input) + { + self::expectException(ParseCompileError::class); + + Parser::parse($input, '-'); + } + + public function failsToParseDataProvider() + { + return [ + // Incomplete tag + [''], + ['barbarbarbar'], + + // Unclosed parameter + [''], + + // Unclosed tag + ['bar'], + + // Trailing closing tag + [''], + ['abc'], + [''], + + // Open/close tag mismatch + ['bar'], + + // Nesting error + [''], + + // Invalid parameter name + [''], + + // Unclosed variable + ['${foo'], + ['${${foo}'], + + // Unclosed array + ['$foo[bar'], + + // Incomplete variable + ['$'], + ['foo$'], + ['foo${}'], + + // Incomplete shorthands + ['?{foo|bar}'], + ['?{foo|bar|baz'], + ['?{foo|'], + ['?{foo}'], + ['?{'], + ['~{foo|bar}'], + ['~{foo|bar|baz'], + ['~{foo|'], + ['~{foo}'], + ['~{'], + ]; + } } -- cgit v1.2.3-70-g09d2