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:
parent
129d59f79f
commit
70787a19bf
@ -2,6 +2,7 @@
|
||||
|
||||
## master
|
||||
- Debug mode - provides data for position, line and column. Disabled by default.
|
||||
- Performace touches
|
||||
<br>
|
||||
<br>
|
||||
|
||||
|
@ -14,6 +14,7 @@ class Lexer implements \IteratorAggregate, PositionAware
|
||||
|
||||
/**
|
||||
* @param iterable $byteChunks
|
||||
* @param bool $debug
|
||||
*/
|
||||
public function __construct($byteChunks, $debug = false)
|
||||
{
|
||||
|
@ -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 [
|
||||
|
Loading…
x
Reference in New Issue
Block a user