1
0
mirror of https://github.com/halaxa/json-machine.git synced 2025-03-15 17:09:39 +01:00

test Lexer provides locational data when debug disabled

This commit is contained in:
Filip Halaxa 2021-12-16 17:38:31 +01:00
parent 129d59f79f
commit 70787a19bf
3 changed files with 23 additions and 0 deletions

View File

@ -2,6 +2,7 @@
## master
- Debug mode - provides data for position, line and column. Disabled by default.
- Performace touches
<br>
<br>

View File

@ -14,6 +14,7 @@ class Lexer implements \IteratorAggregate, PositionAware
/**
* @param iterable $byteChunks
* @param bool $debug
*/
public function __construct($byteChunks, $debug = false)
{

View File

@ -65,6 +65,27 @@ class LexerTest extends \PHPUnit_Framework_TestCase
}
}
/**
* @param string $formattedJsonFilePath
* @dataProvider dataProvidesLocationalData
*/
public function testProvidesLocationalDataWhenDebugDisabled($formattedJsonFilePath)
{
$json = file_get_contents($formattedJsonFilePath);
$lexer = new Lexer(new StringChunks($json), false);
$expectedTokens = $this->expectedTokens();
$i = 0;
foreach ($lexer as $token) {
$i++;
$expectedToken = array_shift($expectedTokens);
$this->assertEquals($expectedToken[0], $token, 'token failed with expected token #' . $i);
$this->assertEquals(1, $lexer->getLine(), 'line failed with expected token #' . $i);
$this->assertEquals(0, $lexer->getColumn(), 'column failed with expected token #' . $i);
}
}
public function dataProvidesLocationalData()
{
return [