Skip to content

Commit

Permalink
Add tests for ReadAt of ByteView
Browse files Browse the repository at this point in the history
The tests pass if ReadAt returns in errors for invalid values of offset.
The patch also adds check for error to be returned when dest is larger
in size than source.
  • Loading branch information
sum12 committed Oct 29, 2019
1 parent 611e8ac commit a3fc0fe
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions byteview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ func TestByteViewSlice(t *testing.T) {
}
}

func TestByteViewReadAt(t *testing.T) {
tests := []int64{
-1,
5,
}
bv := ByteView{b: []byte("xy")}
for i, tt := range tests {
if _, re := bv.ReadAt([]byte("ab"), tt); re == nil {
name := fmt.Sprintf("test %d", i)
t.Errorf("got nil; want error, for offset %d", name, tt)
}
}
if _, re := bv.ReadAt([]byte("abcd"), 0); re == nil {
t.Errorf("got nil; want error, when dest is larger")
}
}

func min(a, b int) int {
if a < b {
return a
Expand Down

0 comments on commit a3fc0fe

Please sign in to comment.