Skip to content

Commit 45d107a

Browse files
committed
Add tests for ReadAt of ByteView
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.
1 parent 611e8ac commit 45d107a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

byteview_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ func TestByteViewSlice(t *testing.T) {
139139
}
140140
}
141141

142+
func TestByteViewReadAt(t *testing.T) {
143+
tests := []int64{
144+
-1,
145+
5,
146+
}
147+
bv := ByteView{b: []byte("xy")}
148+
for i, tt := range tests {
149+
if _, re := bv.ReadAt([]byte("ab"), tt); re == nil {
150+
name := fmt.Sprintf("test %d", i)
151+
t.Errorf("got nil; want error, for offset %d", name, tt)
152+
}
153+
}
154+
if _, re := bv.ReadAt([]byte("abcd"), 0); re == nil {
155+
t.Errorf("got nil; want error, when dest is larger")
156+
}
157+
}
158+
142159
func min(a, b int) int {
143160
if a < b {
144161
return a

0 commit comments

Comments
 (0)