Check that Slice has correct position after matching

This commit is contained in:
2024-09-09 15:00:17 -06:00
parent f75904ca93
commit 8943da5aee
2 changed files with 26 additions and 20 deletions

View File

@ -27,26 +27,35 @@ func TestSlice(t *testing.T) {
s := rapid.SliceOfN(rapid.Byte(), 1, -1).Draw(t, "s")
input := rapid.SliceOfN(rapid.Byte(), len(s), -1).
Filter(notP(hasPrefix(s))).Draw(t, "input")
out, err := gigaparsec.Parse(gigaparsec.Slice(s), cursor.NewSlice(input))
start := gigaparsec.MakeState(cursor.NewSlice(input))
consumed, result, err := gigaparsec.Slice(s)(start)
test.ErrorAs(t, err, &gigaparsec.ParseError{})
test.SliceEmpty(t, out)
test.False(t, consumed, test.Sprint("expected consumed to be false"))
test.SliceEmpty(t, result.Value)
}))
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]
out, err := gigaparsec.Parse(gigaparsec.Slice(s), cursor.NewSlice(input))
start := gigaparsec.MakeState(cursor.NewSlice(input))
consumed, result, err := gigaparsec.Slice(s)(start)
test.ErrorAs(t, err, &gigaparsec.ParseError{})
test.SliceEmpty(t, out)
test.False(t, consumed, test.Sprint("expected consumed to be false"))
test.SliceEmpty(t, result.Value)
}))
t.Run("fails when read fails", Todo)
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]
out, err := gigaparsec.Parse(gigaparsec.Slice(s), cursor.NewSlice(input))
start := gigaparsec.MakeState(cursor.NewSlice(input))
consumed, result, err := gigaparsec.Slice(s)(start)
test.NoError(t, err)
test.SliceEqOp(t, s, out)
test.True(t, consumed, test.Sprint("expected consumed to be true"))
test.SliceEqOp(t, s, result.Value)
test.EqOp(t, uint64(len(s)), result.State.Pos())
}))
t.Run("next state has correct position", Todo)
}