Compare commits

...

2 Commits

Author SHA1 Message Date
776b513c44 Return correct next state from Read 2024-09-27 09:39:20 -06:00
e6debbd7dc Improve MatchSlice test output 2024-09-27 09:37:35 -06:00
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) {
nread, err := s.r.ReadAt(dst, int64(s.pos))
if n > 0 {
s.pos += uint64(n)
if nread > 0 {
s.pos += uint64(nread)
}
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) {
s := rapid.SliceOfN(rapid.Byte(), 1, -1).Draw(t, "s")
inputLen := rapid.IntRange(0, len(s)-1).Draw(t, "inputLen")
input := s[:inputLen]
input := rapid.Map(rapid.IntRange(0, len(s)-1),
func(n int) []byte { return s[:n] }).Draw(t, "inputLen")
assertParseFails(t, input, gigaparsec.MatchSlice(s))
}))
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) {
input := rapid.SliceOfN(rapid.Byte(), 1, -1).Draw(t, "input")
sLen := rapid.IntRange(0, len(input)).Draw(t, "sLen")
s := input[:sLen]
s := rapid.Map(rapid.IntRange(0, len(input)),
func(n int) []byte { return input[:n] }).Draw(t, "s")
start := gigaparsec.MakeState(bytes.NewReader(input))
result, err := gigaparsec.MatchSlice(s)(start)