Test Slice with a failing reader
This commit is contained in:
@ -2,10 +2,12 @@ package gigaparsec_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"git.codemonkeysoftware.net/b/gigaparsec"
|
||||
"git.codemonkeysoftware.net/b/gigaparsec/cursor"
|
||||
ptest "git.codemonkeysoftware.net/b/gigaparsec/test"
|
||||
"github.com/shoenig/test"
|
||||
"github.com/shoenig/test/must"
|
||||
"pgregory.net/rapid"
|
||||
@ -49,7 +51,14 @@ func TestSlice(t *testing.T) {
|
||||
input := s[:inputLen]
|
||||
assertParseFails(t, input, gigaparsec.Slice(s))
|
||||
}))
|
||||
t.Run("fails when read fails", Todo)
|
||||
t.Run("fails when read fails", rapid.MakeCheck(func(t *rapid.T) {
|
||||
expectedErr := rapid.Map(rapid.StringN(0, 100, -1), errors.New).Draw(t, "err")
|
||||
r := ptest.ErrReaderAt(expectedErr)
|
||||
c := cursor.NewReaderAt(r)
|
||||
s := rapid.SliceOfN(rapid.Byte(), 0, 100).Draw(t, "s")
|
||||
_, err := gigaparsec.Slice(s)(gigaparsec.MakeState(c))
|
||||
test.ErrorIs(t, err, expectedErr)
|
||||
}))
|
||||
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")
|
||||
|
Reference in New Issue
Block a user