From 4cbe9ce68311566f512f35eafa2f9131bc69541c Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Wed, 11 Sep 2024 14:52:27 -0600 Subject: [PATCH] Added tests for Cursor.At --- cursor/cursor_test.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/cursor/cursor_test.go b/cursor/cursor_test.go index 1b7bf33..3fa3e8e 100644 --- a/cursor/cursor_test.go +++ b/cursor/cursor_test.go @@ -55,7 +55,7 @@ func testCursor[C cursor.Cursor[byte]](t *testing.T, makeCursor func([]byte) C) t.Run("next cursor reads next input", rapid.MakeCheck(func(t *rapid.T) { const maxLen = 100 data := rapid.SliceOfN(rapid.Byte(), 1, maxLen).Draw(t, "data") - skip := rapid.IntRange(0, len(data)-1).Draw(t, "data") + skip := rapid.IntRange(0, len(data)-1).Draw(t, "skip") c := makeCursor(data) _, next, err := c.Read(make([]byte, skip)) @@ -84,7 +84,22 @@ func testCursor[C cursor.Cursor[byte]](t *testing.T, makeCursor func([]byte) C) test.NoError(t, err) test.EqOp(t, data[pos], dst[0]) })) - t.Run("Pos", Todo) + t.Run("Pos returns correct position after At", rapid.MakeCheck(func(t *rapid.T) { + var data []byte + pos := rapid.Uint64().Draw(t, "pos") + c := makeCursor(data).At(pos) + test.EqOp(t, pos, c.Pos()) + })) + t.Run("Pos returns correct position after Read", rapid.MakeCheck(func(t *rapid.T) { + const maxLen = 100 + data := rapid.SliceOfN(rapid.Byte(), 1, maxLen).Draw(t, "data") + skip := rapid.Uint64Range(0, uint64(len(data)-1)).Draw(t, "skip") + c := makeCursor(data) + + _, next, err := c.Read(make([]byte, skip)) + must.NoError(t, err) + test.EqOp(t, skip, next.Pos()) + })) } func TestSliceCursor(t *testing.T) {