Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
Revert "Stream: removed code that I don't know what is doing"
Browse files Browse the repository at this point in the history
This reverts commit 35a55af.
  • Loading branch information
dg committed Sep 13, 2019
1 parent d462da8 commit 71a61ac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/Tokenizer/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ protected function scan(array $wanted, bool $onlyFirst, bool $advance, bool $str
$pos = $this->position + ($prev ? -1 : 1);
do {
if (!isset($this->tokens[$pos])) {
if (!$wanted && $advance && !$prev && $pos <= count($this->tokens)) {
$this->next();
}
return $res;
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Tokenizer/Stream.join.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ test(function () {

$stream->position = 2;
Assert::null($stream->nextValue());
Assert::same(2, $stream->position);
Assert::same(3, $stream->position);

$stream->position = 2;
Assert::null($stream->nextValue());
Assert::null($stream->nextValue(T_STRING, T_DNUMBER, T_WHITESPACE));
Assert::same(2, $stream->position);
Assert::same(3, $stream->position);

$stream->position = 2;
Assert::same('', $stream->joinAll());
Assert::same('', $stream->joinAll(T_STRING, T_DNUMBER, T_WHITESPACE));
Assert::same(2, $stream->position);
Assert::same(3, $stream->position);

$stream->position = 2;
Assert::same('', $stream->joinUntil(T_STRING, T_DNUMBER, T_WHITESPACE));
Expand Down Expand Up @@ -133,7 +133,7 @@ test(function () {
Assert::exception(function () use ($stream) {
$stream->consumeValue();
}, Nette\Tokenizer\Exception::class, 'Unexpected end of string');
Assert::same(3, $stream->position);
Assert::same(4, $stream->position);

$stream->position = 3;
Assert::exception(function () use ($stream) {
Expand Down
8 changes: 4 additions & 4 deletions tests/Tokenizer/Stream.traversing.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ test(function () {
$stream->position = 2;
Assert::null($stream->nextToken());
Assert::null($stream->nextToken());
Assert::same(2, $stream->position);
Assert::same(3, $stream->position);

$stream->position = 2;
Assert::null($stream->nextToken());
Assert::null($stream->nextToken(T_STRING, T_DNUMBER, T_WHITESPACE));
Assert::same(2, $stream->position);
Assert::same(3, $stream->position);

$stream->position = 2;
Assert::same([], $stream->nextAll());
Assert::same([], $stream->nextAll(T_STRING, T_DNUMBER, T_WHITESPACE));
Assert::same(2, $stream->position);
Assert::same(3, $stream->position);

$stream->position = 2;
Assert::same([], $stream->nextUntil(T_STRING, T_DNUMBER, T_WHITESPACE));
Expand Down Expand Up @@ -154,7 +154,7 @@ test(function () {
Assert::exception(function () use ($stream) {
$stream->consumeToken();
}, Nette\Tokenizer\Exception::class, 'Unexpected end of string');
Assert::same(3, $stream->position);
Assert::same(4, $stream->position);

$stream->position = 3;
Assert::exception(function () use ($stream) {
Expand Down

0 comments on commit 71a61ac

Please sign in to comment.