0
0
mirror of https://github.com/pmmp/ext-encoding.git synced 2025-10-11 15:14:58 +00:00
Files
ext-encoding/tests/varint/read-update-offset.phpt
Dylan K. Taylor eb9610a102 Split up ByteBuffer into reader & writer parts
closes #13

This prevents accidentally writing when reading is intended, and vice
versa.
It also allows specialising the APIs and constructors.
2025-09-06 17:12:57 +01:00

32 lines
715 B
PHP

--TEST--
VarInt::read(Un)Signed(Int|Long)() must correctly update the internal offset
--EXTENSIONS--
encoding
--FILE--
<?php
use pmmp\encoding\ByteBufferReader;
use pmmp\encoding\VarInt;
function test(\Closure $function, int $size) : void{
$varint = str_repeat(str_repeat("\x80", $size - 1) . "\x00", 3);
$buffer = new ByteBufferReader($varint);
$originalOffset = $size;
$buffer->setOffset($originalOffset);
$function($buffer);
var_dump($buffer->getOffset() === $size + $originalOffset);
}
test(VarInt::readUnsignedInt(...), 5);
test(VarInt::readSignedInt(...), 5);
test(VarInt::readUnsignedLong(...), 10);
test(VarInt::readSignedLong(...), 10);
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
bool(true)