Test Repeat success/failure
This commit is contained in:
parent
2d6f091e0b
commit
5e6eafef64
@ -138,8 +138,22 @@ func TestEnd(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRepeat(t *testing.T) {
|
||||
t.Run("fails when number of successes is less than minCount", Todo)
|
||||
t.Run("succeeds when number of successes is greater than minCount", Todo)
|
||||
t.Run("succeeds iff number of successes ≥ minCount", rapid.MakeCheck(func(t *rapid.T) {
|
||||
const good byte = 'o'
|
||||
const bad byte = 'x'
|
||||
const maxParses = 100
|
||||
|
||||
minCount := rapid.IntRange(0, maxParses).Draw(t, "minCount")
|
||||
successes := rapid.IntRange(0, maxParses).Draw(t, "successes")
|
||||
|
||||
input := append(ptest.SliceOfN(good, successes), bad)
|
||||
p := gigaparsec.Repeat(minCount, gigaparsec.Match(good))
|
||||
result, err := p(gigaparsec.MakeState(bytes.NewReader(input)))
|
||||
|
||||
must.NoError(t, err)
|
||||
success, _, _ := result.Status()
|
||||
test.EqOp(t, successes >= minCount, success, test.Sprint("expected successes ≥ minCount"))
|
||||
}))
|
||||
t.Run("consumes iff at least one application consumes", Todo)
|
||||
t.Run("fails on error", Todo)
|
||||
t.Run("position is unchanged on failure", Todo)
|
||||
|
@ -26,3 +26,11 @@ func ErrReaderAt(err error) io.ReaderAt {
|
||||
func StateIsAt[Input any](t test.T, s gigaparsec.State[Input], pos uint64) {
|
||||
test.EqOp(t, pos, s.Pos(), test.Sprintf("expected parser state to be at position %d, got %d", pos, s.Pos()))
|
||||
}
|
||||
|
||||
func SliceOfN[T any](value T, n int) []T {
|
||||
s := make([]T, n)
|
||||
for i := range s {
|
||||
s[i] = value
|
||||
}
|
||||
return s
|
||||
}
|
Loading…
Reference in New Issue
Block a user