Compare commits
2 Commits
82ade62274
...
776b513c44
Author | SHA1 | Date | |
---|---|---|---|
776b513c44 | |||
e6debbd7dc |
@ -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 n > 0 {
|
if nread > 0 {
|
||||||
s.pos += uint64(n)
|
s.pos += uint64(nread)
|
||||||
}
|
}
|
||||||
return uint64(nread), s, err
|
return uint64(nread), s, err
|
||||||
}
|
}
|
||||||
|
@ -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")
|
||||||
inputLen := rapid.IntRange(0, len(s)-1).Draw(t, "inputLen")
|
input := rapid.Map(rapid.IntRange(0, len(s)-1),
|
||||||
input := s[:inputLen]
|
func(n int) []byte { return s[:n] }).Draw(t, "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")
|
||||||
sLen := rapid.IntRange(0, len(input)).Draw(t, "sLen")
|
s := rapid.Map(rapid.IntRange(0, len(input)),
|
||||||
s := input[:sLen]
|
func(n int) []byte { return input[:n] }).Draw(t, "s")
|
||||||
start := gigaparsec.MakeState(bytes.NewReader(input))
|
start := gigaparsec.MakeState(bytes.NewReader(input))
|
||||||
|
|
||||||
result, err := gigaparsec.MatchSlice(s)(start)
|
result, err := gigaparsec.MatchSlice(s)(start)
|
||||||
|
Loading…
Reference in New Issue
Block a user