Start on Bind tests
This commit is contained in:
parent
828f804d8c
commit
6277f7bb72
3
TODO.txt
3
TODO.txt
@ -1,4 +1,3 @@
|
||||
Test RuneReader
|
||||
Test Regexp
|
||||
Add Sequence parsers (generated)
|
||||
Add SPDX tags
|
||||
What's Megaparsec got that we ain't got?
|
||||
|
@ -81,7 +81,29 @@ func TestChoose(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBind(t *testing.T) {
|
||||
Todo(t)
|
||||
t.Run("fails without constructing second parser if the first parser fails", Todo)
|
||||
t.Run("returns an error without constructing second parser if the first returns an error", Todo)
|
||||
t.Run("fails if the second parser fails", Todo)
|
||||
t.Run("returns an error if the second parser returns an error", Todo)
|
||||
t.Run("succeeds if both parsers succeed", rapid.MakeCheck(func(t *rapid.T) {
|
||||
// s := rapid.SliceOfN(rapid.Byte(), 0, 100)
|
||||
t.Errorf("TODO")
|
||||
}))
|
||||
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) {
|
||||
return gigaparsec.Succeed(consume, struct{}{}, s, gigaparsec.MessageOK(0)), nil
|
||||
}
|
||||
}
|
||||
pConsume := rapid.Bool().Draw(t, "pShouldConsume")
|
||||
qConsume := rapid.Bool().Draw(t, "qShouldConsume")
|
||||
p := makeParser(pConsume)
|
||||
q := func(struct{}) gigaparsec.Parser[byte, struct{}] { return makeParser(qConsume) }
|
||||
|
||||
result, err := gigaparsec.Bind(p, q)(gigaparsec.MakeState(cursor.NewSlice([]byte{})))
|
||||
must.NoError(t, err)
|
||||
must.EqOp(t, pConsume || qConsume, result.Consumed())
|
||||
}))
|
||||
}
|
||||
|
||||
func TestReturn(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user