Skip to content

Commit

Permalink
Merge pull request #788 from msmakouz/bugfix/buffer-offset
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed Sep 13, 2022
1 parent e1ca142 commit 17c9e6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Lexer/Buffer.php
Expand Up @@ -53,7 +53,7 @@ public function next(): Byte|Token|null
$this->buffer[] = $n;
}

if ($n !== null) {
if ($n !== null && $n->offset !== null) {
$this->offset = $n->offset;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/BufferTest.php
Expand Up @@ -9,6 +9,7 @@
use Spiral\Stempler\Lexer\Byte;
use Spiral\Stempler\Lexer\StreamInterface;
use Spiral\Stempler\Lexer\StringStream;
use Spiral\Stempler\Lexer\Token;

class BufferTest extends TestCase
{
Expand Down Expand Up @@ -120,6 +121,10 @@ public function testOffset(): void

$this->assertEquals(new Byte(2, 'c'), $src->next());
$this->assertEquals(2, $src->getOffset());

$src = new Buffer($this->generateToken(new StringStream('abc')));
$this->assertEquals(new Token(0, null, 'a'), $src->next());
$this->assertEquals(0, $src->getOffset());
}

public function testLookupBytes(): void
Expand Down Expand Up @@ -148,4 +153,11 @@ private function generate(StreamInterface $src)
yield new Byte($src->getOffset(), $src->peak());
}
}

private function generateToken(StreamInterface $src): \Generator
{
while (!$src->isEOI()) {
yield new Token(0, null, $src->peak());
}
}
}

0 comments on commit 17c9e6b

Please sign in to comment.