diff options
author | Laria Carolin Chabowski <laria@laria.me> | 2020-09-15 22:44:16 +0200 |
---|---|---|
committer | Laria Carolin Chabowski <laria@laria.me> | 2020-09-15 22:44:16 +0200 |
commit | c6801426167f99f1ea3da8730f27877b594da055 (patch) | |
tree | b0654df7765d40e930270f3af07e1f0f0249dba6 /tests | |
parent | 71176122872e7d200167cd77d48ed30fda95b3ae (diff) | |
download | ste-c6801426167f99f1ea3da8730f27877b594da055.tar.gz ste-c6801426167f99f1ea3da8730f27877b594da055.tar.bz2 ste-c6801426167f99f1ea3da8730f27877b594da055.zip |
Tests: Test parsing invalid input
>95% coverage of the parser, hooray!
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/ParserTest.php | 81 |
1 files changed, 81 insertions, 0 deletions
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 + ['<ste:foo'], + ['<ste:'], + ['<ste:>'], + ['<ste:foo /'], + + // Incomplete closing tag + ['<ste:foo>bar</'], + ['<ste:foo>bar</ste'], + ['<ste:foo>bar</ste:'], + ['<ste:foo>bar</ste:foo'], + ['<ste:foo></'], + ['<ste:foo></ste'], + ['<ste:foo></ste:'], + ['<ste:foo></ste:foo'], + + // Missing parameter value + ['<ste:foo bar= />'], + + // Unclosed parameter + ['<ste:foo bar=" />'], + ['<ste:foo bar="baz />'], + + // Unclosed tag + ['<ste:foo>bar'], + + // Trailing closing tag + ['</ste:foo>'], + ['abc</ste:foo>'], + ['<ste:foo></ste:foo></ste:foo>'], + + // Open/close tag mismatch + ['<ste:foo>bar</ste:baz>'], + + // Nesting error + ['<ste:foo><ste:bar></ste:foo></ste:bar>'], + + // Invalid parameter name + ['<ste:foo $bar />'], + + // 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}'], + ['~{'], + ]; + } } |