From 6277f7bb72286664fbd2457505cc6dd6b953e1a5 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Fri, 13 Sep 2024 14:50:12 -0600 Subject: [PATCH] Start on Bind tests --- TODO.txt | 3 +-- parser_test.go | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/TODO.txt b/TODO.txt index c0c7e02..f102642 100644 --- a/TODO.txt +++ b/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? diff --git a/parser_test.go b/parser_test.go index 1096b8c..174b95c 100644 --- a/parser_test.go +++ b/parser_test.go @@ -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) {