mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-07-04 05:26:51 -04:00
remaining string tests
This commit is contained in:
@ -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")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user