Add tests for ReadBytesMaxInto(..., nil)

This commit is contained in:
Jakob Borg 2014-04-09 10:09:41 +02:00
parent 711587492c
commit c2f0c2225a

View File

@ -56,7 +56,7 @@ func TestBytesGiven(t *testing.T) {
} }
} }
func TestReadMaxInto(t *testing.T) { func TestReadBytesMaxInto(t *testing.T) {
var max = 64 var max = 64
for tot := 32; tot < 128; tot++ { for tot := 32; tot < 128; tot++ {
for diff := -32; diff <= 32; diff++ { for diff := -32; diff <= 32; diff++ {
@ -80,3 +80,27 @@ func TestReadMaxInto(t *testing.T) {
} }
} }
} }
func TestReadBytesMaxIntoNil(t *testing.T) {
for tot := 42; tot < 72; tot++ {
for max := 0; max < 128; max++ {
var b = new(bytes.Buffer)
var r = NewReader(b)
var w = NewWriter(b)
var toWrite = make([]byte, tot)
w.WriteBytes(toWrite)
var bs = r.ReadBytesMaxInto(max, nil)
var read = len(bs)
if max == 0 || tot <= max {
if read != tot {
t.Errorf("Incorrect read bytes, wrote=%d, max=%d, read=%d", tot, max, read)
}
} else if r.err != ErrElementSizeExceeded {
t.Errorf("Unexpected non-ErrElementSizeExceeded error for wrote=%d, max=%d, read=%d: %v", tot, max, read, r.err)
}
}
}
}