Compare commits

..

No commits in common. "776b513c444033ed77016fe0e6db332c72ec8079" and "82ade622745623ef24c0ab2e4323befa591be915" have entirely different histories.

2 changed files with 6 additions and 6 deletions

View File

@ -127,8 +127,8 @@ type State[In any] struct {
func (s State[In]) Read(dst []In) (n uint64, next State[In], err error) { func (s State[In]) Read(dst []In) (n uint64, next State[In], err error) {
nread, err := s.r.ReadAt(dst, int64(s.pos)) nread, err := s.r.ReadAt(dst, int64(s.pos))
if nread > 0 { if n > 0 {
s.pos += uint64(nread) s.pos += uint64(n)
} }
return uint64(nread), s, err return uint64(nread), s, err
} }

View File

@ -48,8 +48,8 @@ func TestSlice(t *testing.T) {
})) }))
t.Run("fails at end of input", rapid.MakeCheck(func(t *rapid.T) { t.Run("fails at end of input", rapid.MakeCheck(func(t *rapid.T) {
s := rapid.SliceOfN(rapid.Byte(), 1, -1).Draw(t, "s") s := rapid.SliceOfN(rapid.Byte(), 1, -1).Draw(t, "s")
input := rapid.Map(rapid.IntRange(0, len(s)-1), inputLen := rapid.IntRange(0, len(s)-1).Draw(t, "inputLen")
func(n int) []byte { return s[:n] }).Draw(t, "inputLen") input := s[:inputLen]
assertParseFails(t, input, gigaparsec.MatchSlice(s)) assertParseFails(t, input, gigaparsec.MatchSlice(s))
})) }))
t.Run("fails when read fails", rapid.MakeCheck(func(t *rapid.T) { t.Run("fails when read fails", rapid.MakeCheck(func(t *rapid.T) {
@ -63,8 +63,8 @@ func TestSlice(t *testing.T) {
})) }))
t.Run("succeeds when contents match", rapid.MakeCheck(func(t *rapid.T) { t.Run("succeeds when contents match", rapid.MakeCheck(func(t *rapid.T) {
input := rapid.SliceOfN(rapid.Byte(), 1, -1).Draw(t, "input") input := rapid.SliceOfN(rapid.Byte(), 1, -1).Draw(t, "input")
s := rapid.Map(rapid.IntRange(0, len(input)), sLen := rapid.IntRange(0, len(input)).Draw(t, "sLen")
func(n int) []byte { return input[:n] }).Draw(t, "s") s := input[:sLen]
start := gigaparsec.MakeState(bytes.NewReader(input)) start := gigaparsec.MakeState(bytes.NewReader(input))
result, err := gigaparsec.MatchSlice(s)(start) result, err := gigaparsec.MatchSlice(s)(start)