Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function parse(string $pattern) : Pattern\TypePattern

public function getAST(string $pattern) : AST\Pattern
{
if($pattern === '') {
return new AST\Pattern(new AST\Type(''));
}

$this->lexer->setInput($pattern);
return $this->getPattern();
}
Expand Down
28 changes: 28 additions & 0 deletions tests/MatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,32 @@ public static function nullExamples()
],
];
}

public static function emptyPatternString()
{
return [
[
'', '', true,
'123', '', false,
' ', '', false,
null, '', false,
1, '', false,
0, '', false,
'{"name": "123"}', '{"name": ""}', false,
'{"name": ""}', '{"name": ""}', true,
],
];
}

/**
* @dataProvider emptyPatternString
*/
public function test_empty_pattern_in_the_json($value, $pattern, $expectedResult)
{
$factory = new SimpleFactory();
$matcher = $factory->createMatcher();

$match = $matcher->match($value, $pattern);
$this->assertSame($expectedResult, $match);
}
}