From 45d107ab3eada0be7d3fd66359b3c2fefdae5d45 Mon Sep 17 00:00:00 2001 From: sum12 Date: Tue, 29 Oct 2019 16:57:40 +0100 Subject: [PATCH] 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. --- byteview_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/byteview_test.go b/byteview_test.go index a09757aa..835e18fd 100644 --- a/byteview_test.go +++ b/byteview_test.go @@ -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