~earboxer/bare-mess-php

dd42572c28ab76457fa26de3cc96a17a0e8469c4 — Zach DeCook 1 year, 11 months ago 7de6200 master v0.2.0
tests: Add example values from spec
1 files changed, 29 insertions(+), 0 deletions(-)

M tests/PrimitivesTest.php
M tests/PrimitivesTest.php => tests/PrimitivesTest.php +29 -0
@@ 8,6 8,7 @@ use BareMess\Example\PublicKey;
use BareMess\{I8,I16,I32,I64};
use BareMess\Integer;
use BareMess\Nothing;
use BareMess\Str;
use BareMess\{U8,U16,U32,U64};
use BareMess\UInt;
use PHPUnit\Framework\TestCase;


@@ 54,6 55,12 @@ class PrimitivesTest extends TestCase
        $pk4 = new PublicKey($mess);
        $this->assertEquals('', $mess);
        $this->assertEquals($pk3->get(), $pk4->get());

        $mess = "\x10\xaa\xee\xff\xee\xdd\xcc\xbb\xaa\xee\xdd\xcc\xbb\xee\xdd\xcc\xbb";
        $data = new Str($mess);
        $this->assertEquals('', $mess);
        $this->assertEquals("\xaa\xee\xff\xee\xdd\xcc\xbb\xaa\xee\xdd\xcc\xbb\xee\xdd\xcc\xbb", $data->get());
        $this->assertEquals("\x10\xaa\xee\xff\xee\xdd\xcc\xbb\xaa\xee\xdd\xcc\xbb\xee\xdd\xcc\xbb", $data->mess());
    }

    public function testEnum()


@@ 203,6 210,12 @@ class PrimitivesTest extends TestCase
        $this->assertEquals('', $mess, "Whole mess was not parsed.");
        $this->assertEquals(str_pad('', 141, 'L'), $string3);
        $this->assertEquals("\x8D\x01" . str_pad('', 141, 'L'), Bare::mess($string3));

        $mess = "\x04\x42\x41\x52\x45";
        $string4 = new Str($mess);
        $this->assertEquals('', $mess);
        $this->assertEquals("BARE", $string4->get());
        $this->assertEquals("\x04\x42\x41\x52\x45", $string4->mess());
    }

    public function testUInt()


@@ 269,6 282,22 @@ class PrimitivesTest extends TestCase
        $this->assertEquals(0xDEADBEEF, $u32->get());
        $this->assertEquals("\xEF\xBE\xAD\xDE", $u32->mess());

        $mess = "\x00\x00\x00\x00";
        $u32 = new U32($mess);
        $this->assertEquals("", $mess);
        $this->assertEquals(0, $u32->get());
        $this->assertEquals("\x00\x00\x00\x00", $u32->mess());
        $mess = "\x01\x00\x00\x00";
        $u32 = new U32($mess);
        $this->assertEquals("", $mess);
        $this->assertEquals(1, $u32->get());
        $this->assertEquals("\x01\x00\x00\x00", $u32->mess());
        $mess = "\xFF\x00\x00\x00";
        $u32 = new U32($mess);
        $this->assertEquals("", $mess);
        $this->assertEquals(255, $u32->get());
        $this->assertEquals("\xFF\x00\x00\x00", $u32->mess());

        // On most computers this decade, this will only work as U63.
        $mess = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x7F";
        $u64 = new U64($mess);