mirror of
https://github.com/pmmp/ext-encoding.git
synced 2025-10-11 15:14:58 +00:00
closes #13 This prevents accidentally writing when reading is intended, and vice versa. It also allows specialising the APIs and constructors.
32 lines
715 B
PHP
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)
|