~earboxer/bare-mess-php

c9e497b9aed65a78d4f9963c292457b32adcc3ee — Zach DeCook 3 years ago cee6e38
* Primitives: Construct and support bool
2 files changed, 19 insertions(+), 0 deletions(-)

M src/Bare.php
M tests/PrimitivesTest.php
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();