Adjust lexer position

This commit is contained in:
Andrea Marco Sartori 2023-06-08 17:47:10 +02:00
parent 263de30577
commit c9ecf6fe6c
3 changed files with 13 additions and 13 deletions

View File

@ -32,7 +32,7 @@ final class Lexer implements IteratorAggregate
*
* @var int
*/
private int $position = 1;
private int $position = 0;
/**
* Instantiate the class.

View File

@ -16,9 +16,9 @@ it('lets the user handle syntax errors', function () {
JsonParser::parse('{a}')
->onSyntaxError(function (SyntaxException $e) {
expect($e)
->getMessage()->toBe("Syntax error: unexpected 'a' at position 2")
->getMessage()->toBe("Syntax error: unexpected 'a' at position 1")
->value->toBe('a')
->position->toBe(2);
->position->toBe(1);
})
->traverse();
});

View File

@ -4,51 +4,51 @@ return [
[
'json' => 'a[1, "", 3.14, [], {}]',
'unexpected' => 'a',
'position' => 1,
'position' => 0,
],
[
'json' => '[b1, "", 3.14, [], {}]',
'unexpected' => 'b',
'position' => 2,
'position' => 1,
],
[
'json' => '[1,c "", 3.14, [], {}]',
'unexpected' => 'c',
'position' => 4,
'position' => 3,
],
[
'json' => '[1, d"", 3.14, [], {}]',
'unexpected' => 'd',
'position' => 5,
'position' => 4,
],
[
'json' => '[1, "", e3.14, [], {}]',
'unexpected' => 'e',
'position' => 9,
'position' => 8,
],
[
'json' => '[1, "", 3.14, []f, {}]',
'unexpected' => 'f',
'position' => 18,
'position' => 17,
],
[
'json' => '[1, "", 3.14, [], g{}]',
'unexpected' => 'g',
'position' => 19,
'position' => 18,
],
[
'json' => '[1, "", 3.14, [], {h}]',
'unexpected' => 'h',
'position' => 20,
'position' => 19,
],
[
'json' => '[1, "", 3.14, [], {}i]',
'unexpected' => 'i',
'position' => 21,
'position' => 20,
],
[
'json' => '[1, "", 3.14, [], {}]j',
'unexpected' => 'j',
'position' => 22,
'position' => 21,
],
];