utils: Add test for Packer.Expand

This commit is contained in:
Alex Willmer 2020-03-29 17:43:18 +01:00
parent 18b7662266
commit 12117b1728
1 changed files with 16 additions and 0 deletions

View File

@ -43,6 +43,22 @@ func TestPackerCheckSpace(t *testing.T) {
}
}
func TestPackerExpand(t *testing.T) {
p := Packer{Bytes: []byte{0x01}, Offset: 2}
p.Expand(1)
if !p.Errored() {
t.Fatal("packer.Expand didn't notice packer had out of bounds offset")
}
p = Packer{Bytes: []byte{0x01, 0x02, 0x03}, Offset: 0}
p.Expand(1)
if p.Errored() {
t.Fatalf("packer.Expand unexpectedly had error %s", p.Err)
} else if len(p.Bytes) != 3 {
t.Fatalf("packer.Expand modified byte array, when it didn't need to")
}
}
func TestPackerPackByte(t *testing.T) {
p := Packer{MaxSize: 1}