utils: Add test for Packer.CheckSpace

This commit is contained in:
Alex Willmer 2020-03-29 17:42:47 +01:00
parent 96109a60ea
commit 18b7662266
1 changed files with 26 additions and 0 deletions

View File

@ -17,6 +17,32 @@ const (
BoolSentinal = false
)
func TestPackerCheckSpace(t *testing.T) {
p := Packer{Offset: -1}
p.CheckSpace(1)
if !p.Errored() {
t.Fatal("Expected errNegativeOffset")
}
p = Packer{}
p.CheckSpace(-1)
if !p.Errored() {
t.Fatal("Expected errInvalidInput")
}
p = Packer{Bytes: []byte{0x01}, Offset: 1}
p.CheckSpace(1)
if !p.Errored() {
t.Fatal("Expected errBadLength")
}
p = Packer{Bytes: []byte{0x01}, Offset: 2}
p.CheckSpace(0)
if !p.Errored() {
t.Fatal("Expected errBadLength, due to out of bounds offset")
}
}
func TestPackerPackByte(t *testing.T) {
p := Packer{MaxSize: 1}