1
0
mirror of https://github.com/pmmp/ext-encoding.git synced 2024-11-23 13:36:25 +00:00
ext-encoding/tests/update-offset-varint.phpt
Dylan K. Taylor 56673dd789
Split Types class into several new classes
the main benefit of this is the increased difficulty of accidentally
using the wrong byte order due to auto complete - now choosing byte
order is decided by the first character typed.

however, it also reduces the verbosity of the API, though I'm not sure
about the 'LE' and 'BE' class names.
2024-04-10 16:34:24 +01:00

32 lines
706 B
PHP

--TEST--
read(Un)SignedVar(Int|Long)() must correctly update the internal offset
--EXTENSIONS--
encoding
--FILE--
<?php
use pmmp\encoding\ByteBuffer;
use pmmp\encoding\VarInt;
function test(\Closure $function, int $size) : void{
$varint = str_repeat(str_repeat("\x80", $size - 1) . "\x00", 3);
$buffer = new ByteBuffer($varint);
$originalOffset = $size;
$buffer->setReadOffset($originalOffset);
$function($buffer);
var_dump($buffer->getReadOffset() === $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)