mirror of
https://github.com/cerbero90/json-parser.git
synced 2025-01-16 20:48:15 +01:00
Adjust lexer position
This commit is contained in:
parent
263de30577
commit
c9ecf6fe6c
@ -32,7 +32,7 @@ final class Lexer implements IteratorAggregate
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private int $position = 1;
|
||||
private int $position = 0;
|
||||
|
||||
/**
|
||||
* Instantiate the class.
|
||||
|
@ -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();
|
||||
});
|
||||
|
20
tests/fixtures/errors/syntax.php
vendored
20
tests/fixtures/errors/syntax.php
vendored
@ -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,
|
||||
],
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user