Added tests for Cursor.At

This commit is contained in:
Brandon Dyck 2024-09-11 14:52:27 -06:00
parent 1f746ae6de
commit 4cbe9ce683

View File

@ -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) {