M src/Bare.php => src/Bare.php +4 -0
@@ 7,6 7,10 @@ class Bare
public static function construct(& $mess, $startingValue)
{
switch(gettype($startingValue)) {
+ case 'boolean': // bool
+ $val = $mess[0] !== "\0";
+ $mess = substr($mess, 1);
+ return $val;
case 'string': // string
// TODO: Use uint for string's length.
$length = (new U8($mess))->get();
M tests/PrimitivesTest.php => tests/PrimitivesTest.php +15 -0
@@ 10,6 10,21 @@ use PHPUnit\Framework\TestCase;
class PrimitivesTest extends TestCase
{
+ public function testBool()
+ {
+ $mess = "\x00" . '0';
+
+ $bool = Bare::construct($mess, false);
+ $this->assertEquals(false, $bool);
+ $this->assertEquals("\0", Bare::mess($bool, false));
+
+ $bool = Bare::construct($mess, false);
+ $this->assertEquals(true, $bool);
+ $this->assertEquals("\x01", Bare::mess($bool, false));
+
+ $this->assertEquals("", $mess);
+ }
+
public function testData()
{
$pk = new PublicKey();