From 71a61ac0a560c7ef0794b8a67b1ca9cc7c2588fc Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 13 Sep 2019 13:26:19 +0200 Subject: [PATCH] Revert "Stream: removed code that I don't know what is doing" This reverts commit 35a55af9176926abc502a2e20dc533635e6d9884. --- src/Tokenizer/Stream.php | 3 +++ tests/Tokenizer/Stream.join.phpt | 8 ++++---- tests/Tokenizer/Stream.traversing.phpt | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Tokenizer/Stream.php b/src/Tokenizer/Stream.php index b821a7e..8f30101 100644 --- a/src/Tokenizer/Stream.php +++ b/src/Tokenizer/Stream.php @@ -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; } diff --git a/tests/Tokenizer/Stream.join.phpt b/tests/Tokenizer/Stream.join.phpt index 86cf424..72548d9 100644 --- a/tests/Tokenizer/Stream.join.phpt +++ b/tests/Tokenizer/Stream.join.phpt @@ -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)); @@ -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) { diff --git a/tests/Tokenizer/Stream.traversing.phpt b/tests/Tokenizer/Stream.traversing.phpt index d1a01e9..ecef9b9 100644 --- a/tests/Tokenizer/Stream.traversing.phpt +++ b/tests/Tokenizer/Stream.traversing.phpt @@ -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)); @@ -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) {