From dd42572c28ab76457fa26de3cc96a17a0e8469c4 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Tue, 31 May 2022 17:16:58 -0400 Subject: [PATCH] tests: Add example values from spec --- tests/PrimitivesTest.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/PrimitivesTest.php b/tests/PrimitivesTest.php index 3bdf803..b331ecc 100644 --- a/tests/PrimitivesTest.php +++ b/tests/PrimitivesTest.php @@ -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); -- 2.45.2