Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
145 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
/temp | ||
/tools | ||
/vendor | ||
|
||
/composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
ROOT_DIR="$DIR" | ||
|
||
if [[ ! -d "$ROOT_DIR/tools/abnfgen" ]]; then | ||
rm -rf "$ROOT_DIR/temp/abnfgen" | ||
mkdir -p "$ROOT_DIR/temp/abnfgen" | ||
|
||
wget http://www.quut.com/abnfgen/abnfgen-0.20.tar.gz \ | ||
--output-document "$ROOT_DIR/temp/abnfgen.tar.gz" | ||
|
||
tar xf "$ROOT_DIR/temp/abnfgen.tar.gz" \ | ||
--directory "$ROOT_DIR/temp/abnfgen" \ | ||
--strip-components 1 | ||
|
||
cd "$ROOT_DIR/temp/abnfgen" | ||
./configure | ||
make | ||
|
||
mkdir -p "$ROOT_DIR/tools/abnfgen" | ||
mv abnfgen "$ROOT_DIR/tools/abnfgen" | ||
rm -rf "$ROOT_DIR/temp/abnfgen" "$ROOT_DIR/temp/abnfgen.tar.gz" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\PhpDocParser\Parser; | ||
|
||
use Iterator; | ||
use PHPStan\PhpDocParser\Lexer\Lexer; | ||
use Symfony\Component\Process\Process; | ||
|
||
class FuzzyTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
|
||
/** @var Lexer */ | ||
private $lexer; | ||
|
||
/** @var TypeParser */ | ||
private $typeParser; | ||
|
||
/** @var ConstExprParser */ | ||
private $constExprParser; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->lexer = new Lexer(); | ||
$this->typeParser = new TypeParser(); | ||
$this->constExprParser = new ConstExprParser(); | ||
} | ||
|
||
/** | ||
* @dataProvider provideTypeParserData | ||
* @param string $input | ||
*/ | ||
public function testTypeParser(string $input) | ||
{ | ||
$tokens = new TokenIterator($this->lexer->tokenize($input)); | ||
$this->typeParser->parse($tokens); | ||
|
||
$this->assertSame( | ||
Lexer::TOKEN_END, | ||
$tokens->currentTokenType(), | ||
sprintf('Failed to parse input %s', $input) | ||
); | ||
} | ||
|
||
public function provideTypeParserData(): Iterator | ||
{ | ||
return $this->provideFuzzyInputsData('Type'); | ||
} | ||
|
||
/** | ||
* @dataProvider provideConstExprParserData | ||
* @param string $input | ||
*/ | ||
public function testConstExprParser(string $input) | ||
{ | ||
$tokens = new TokenIterator($this->lexer->tokenize($input)); | ||
$this->constExprParser->parse($tokens); | ||
|
||
$this->assertSame( | ||
Lexer::TOKEN_END, | ||
$tokens->currentTokenType(), | ||
sprintf('Failed to parse input %s', $input) | ||
); | ||
} | ||
|
||
public function provideConstExprParserData(): Iterator | ||
{ | ||
return $this->provideFuzzyInputsData('ConstantExpr'); | ||
} | ||
|
||
private function provideFuzzyInputsData(string $startSymbol): Iterator | ||
{ | ||
$inputsDirectory = sprintf('%s/fuzzy/%s', __DIR__ . '/../../../temp', $startSymbol); | ||
|
||
if (is_dir($inputsDirectory)) { | ||
foreach (glob(sprintf('%s/*.tst', $inputsDirectory)) as $file) { | ||
unlink($file); | ||
} | ||
|
||
} else { | ||
mkdir($inputsDirectory, 0777, true); | ||
} | ||
|
||
$process = new Process([ | ||
__DIR__ . '/../../../tools/abnfgen/abnfgen', | ||
'-lx', | ||
'-n', | ||
'1000', | ||
'-d', | ||
$inputsDirectory, | ||
'-s', | ||
$startSymbol, | ||
__DIR__ . '/../../../doc/grammars/type.abnf', | ||
]); | ||
|
||
$process->mustRun(); | ||
|
||
foreach (glob(sprintf('%s/*.tst', $inputsDirectory)) as $file) { | ||
$input = file_get_contents($file); | ||
yield [$input]; | ||
} | ||
} | ||
|
||
} |