remaining string tests

This commit is contained in:
Hayden Parker
2016-02-04 01:02:47 -08:00
parent e6cc4425c6
commit 4823944d59
2 changed files with 20 additions and 2 deletions

View File

@ -23,9 +23,26 @@ func TestReadStringReadsLength(t *testing.T) {
}
func TestReadStringErrWhenEmptySlice(t *testing.T) {
bytes := make([]byte, 0)
_, _, err := ReadString(bytes)
if err != nil && err.Error() != "no string in empty byte slice" {
t.Fatal("ReadString() did not report empty slice error", err)
}
}
func TestReadStringErrWhenStringTooLong(t *testing.T) {
bytes := []byte{0x03, 0x01}
str, remainder, err := ReadString(bytes)
if err != nil && err.Error() != "string longer than provided slice" {
t.Fatal("ReadString() did not report string too long", err)
}
if len(str) != 1 {
t.Fatal("ReadString() did not return the slice as string when too long")
}
if str[0] != 0x01 {
t.Fatal("ReadString() did not return the correct partial string")
}
if len(remainder) != 0 {
t.Fatal("ReadString() returned a remainder when the string was too long")
}
}