1
0
mirror of https://github.com/pmmp/ext-encoding.git synced 2024-11-23 13:36:25 +00:00
ext-encoding/tests/set-write-offset.phpt
Dylan K. Taylor 9a5d74ab2a
Separate read and write offsets
this isn't an ideal solution, but it's the easiest one available and gives time to figure out next steps for the API design.
2024-01-30 14:25:44 +00:00

41 lines
888 B
PHP

--TEST--
Test that ByteBuffer::setWriteOffset() works as expected
--FILE--
<?php
use pmmp\encoding\ByteBuffer;
$buffer = new ByteBuffer("");
$buffer->setWriteOffset(0);
$buffer->writeByteArray("aaaa");
//setting offset at the end of the buffer is allowed and results in buffer extension on the next write
$buffer->setWriteOffset(4);
$buffer->writeByteArray("bbbb");
var_dump($buffer->toString());
$buffer->setWriteOffset(6);
$buffer->writeByteArray("cccc");
var_dump($buffer->toString());
try{
$buffer->setWriteOffset(-1);
}catch(\ValueError $e){
echo $e->getMessage() . PHP_EOL;
}
try{
$buffer->setWriteOffset(11);
}catch(\ValueError $e){
echo $e->getMessage() . PHP_EOL;
}
?>
--EXPECT--
string(8) "aaaabbbb"
string(10) "aaaabbcccc"
Offset must not be less than zero or greater than the buffer size
Offset must not be less than zero or greater than the buffer size