1
0
mirror of https://github.com/pmmp/ext-encoding.git synced 2024-11-27 05:49:01 +00:00
ext-encoding/tests/reserve.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

39 lines
891 B
PHP

--TEST--
Test that reserving works correctly
--FILE--
<?php
use pmmp\encoding\ByteBuffer;
use pmmp\encoding\Byte;
$buffer = new ByteBuffer("");
var_dump($buffer->getReservedLength()); //none
$buffer->reserve(40);
var_dump($buffer->getReservedLength()); //40
var_dump($buffer->toString()); //still empty, we haven't used any space
Byte::writeSigned($buffer, ord("a"));
var_dump($buffer->getReservedLength()); //40
var_dump($buffer->toString());
$buffer->writeByteArray(str_repeat("a", 40)); //cause new allocation, this should double the buffer size to 80
var_dump($buffer->getReservedLength()); //80
var_dump($buffer->toString());
try{
$buffer->reserve(-1);
}catch(\ValueError $e){
echo $e->getMessage() . PHP_EOL;
}
?>
--EXPECT--
int(0)
int(40)
string(0) ""
int(40)
string(1) "a"
int(80)
string(41) "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
Length must be greater than zero