Skip to content

Commit 56d7bb3

Browse files
committed
hex/getHex issue
1 parent 43c8bc2 commit 56d7bb3

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

tests/BufferTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@ public function testSerialize()
8989
$this->assertInstanceOf(\GMP::class, $buffer->getGmp());
9090
}
9191

92+
public function testSerialize2()
93+
{
94+
$hex = '12a05f200'; // 5e9
95+
$dec = gmp_strval(gmp_init($hex, 16), 10);
96+
$bin = pack("H*", $hex);
97+
// $unpacked = unpack("H*", $bin); // [1] => 12a05f2000 <- 5e10
98+
// error_log('$unpacked = ' . print_r($unpacked, true));
99+
$buffer = Buffer::hex($hex);
100+
101+
// Check Binary
102+
$retBinary = $buffer->getBinary();
103+
$this->assertSame($bin, $retBinary);
104+
105+
// Check Hex
106+
$this->assertSame($hex, $buffer->getHex());
107+
108+
// Check Decimal
109+
$this->assertSame($dec, $buffer->getInt());
110+
$this->assertInstanceOf(\GMP::class, $buffer->getGmp());
111+
}
112+
92113
public function testGetSize()
93114
{
94115
$this->assertEquals(1, Buffer::hex('41')->getSize());
@@ -102,9 +123,9 @@ public function testGetSize()
102123
public function getIntVectors(): array
103124
{
104125
return [
105-
['1', '01', 1, ],
126+
['1', '01', 1,],
106127
['1', '01', null,],
107-
['20', '14', 1, ]
128+
['20', '14', 1,]
108129
];
109130
}
110131

@@ -126,8 +147,8 @@ public function testIntConstruct($int, string $expectedHex, int $size = null)
126147
public function getGmpVectors(): array
127148
{
128149
return [
129-
[ gmp_init('0A', 16) ],
130-
[ gmp_init('237852977508946591877284351678975096651401224047304305322504192889595623579202', 10) ],
150+
[gmp_init('0A', 16)],
151+
[gmp_init('237852977508946591877284351678975096651401224047304305322504192889595623579202', 10)],
131152
];
132153
}
133154

0 commit comments

Comments
 (0)