Added Pipe and Match parsers
This commit is contained in:
@ -43,19 +43,19 @@ func TestSlice(t *testing.T) {
|
||||
s := rapid.SliceOfN(rapid.Byte(), 1, -1).Draw(t, "s")
|
||||
input := rapid.SliceOfN(rapid.Byte(), len(s), -1).
|
||||
Filter(not(hasPrefix(s))).Draw(t, "input")
|
||||
assertParseFails(t, input, gigaparsec.Slice(s))
|
||||
assertParseFails(t, input, gigaparsec.MatchSlice(s))
|
||||
}))
|
||||
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]
|
||||
assertParseFails(t, input, gigaparsec.Slice(s))
|
||||
assertParseFails(t, input, gigaparsec.MatchSlice(s))
|
||||
}))
|
||||
t.Run("fails when read fails", rapid.MakeCheck(func(t *rapid.T) {
|
||||
expectedErr := generator.Error().Draw(t, "expectedErr")
|
||||
c := ptest.ErrCursor[byte](expectedErr)
|
||||
s := rapid.SliceOfN(rapid.Byte(), 0, 100).Draw(t, "s")
|
||||
result, err := gigaparsec.Slice(s)(gigaparsec.MakeState(c))
|
||||
result, err := gigaparsec.MatchSlice(s)(gigaparsec.MakeState(c))
|
||||
failed, _, _ := result.Failed()
|
||||
test.ErrorIs(t, err, expectedErr)
|
||||
test.True(t, failed)
|
||||
@ -66,7 +66,7 @@ func TestSlice(t *testing.T) {
|
||||
s := input[:sLen]
|
||||
start := gigaparsec.MakeState(cursor.NewSlice(input))
|
||||
|
||||
result, err := gigaparsec.Slice(s)(start)
|
||||
result, err := gigaparsec.MatchSlice(s)(start)
|
||||
must.NoError(t, err)
|
||||
succeeded, consumed, value, next, _ := result.Succeeded()
|
||||
test.True(t, succeeded)
|
||||
@ -89,6 +89,12 @@ func TestBind(t *testing.T) {
|
||||
// s := rapid.SliceOfN(rapid.Byte(), 0, 100)
|
||||
t.Errorf("TODO")
|
||||
}))
|
||||
/*
|
||||
If the first parser fails, then consumption depends on the first parser.
|
||||
If the first parser succeeds, then bound parser consumes iff either parser succeeded.
|
||||
For BindN:
|
||||
If all parsers before i succeed, bound parser consumes if any parser before i consumed.
|
||||
*/
|
||||
t.Run("consumption on success", rapid.MakeCheck(func(t *rapid.T) {
|
||||
makeParser := func(consume bool) gigaparsec.Parser[byte, struct{}] {
|
||||
return func(s gigaparsec.State[byte]) (gigaparsec.Result[byte, struct{}], error) {
|
||||
|
Reference in New Issue
Block a user