From 4a13ec209d8af5426f221bf137c77df1f418a391 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Wed, 18 Sep 2024 11:46:39 -0600 Subject: [PATCH] Test more Parse failures --- csexp/sexp_test.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/csexp/sexp_test.go b/csexp/sexp_test.go index 851225e..a92eec4 100644 --- a/csexp/sexp_test.go +++ b/csexp/sexp_test.go @@ -44,7 +44,26 @@ func TestParseFails(t *testing.T) { test.Error(t, err) test.Nil(t, parsed) })) - t.Run("with too little input", rapid.MakeCheck(func(t *rapid.T) {})) + t.Run("with too little input", rapid.MakeCheck(func(t *rapid.T) { + sexp := gen.Sexp().Draw(t, "sexp") + b := []byte(sexp.String()) + missing := rapid.IntRange(1, len(b)).Draw(t, "missing") + b = b[:len(b)-missing] + parsed, err := csexp.Parse(b) + test.Error(t, err) + test.Nil(t, parsed) + })) + t.Run("with malformed atom length", rapid.MakeCheck(func(t *rapid.T) { + atom := gen.Atom().Draw(t, "atom") + s := []byte(atom.String()) + changeIdx := rapid.IntRange(0, bytes.IndexByte(s, ':')).Draw(t, "changeIdx") + change := rapid.ByteRange(1, 255).Draw(t, "change") + s[changeIdx] = change + + parsed, err := csexp.Parse(s) + test.Error(t, err) + test.Nil(t, parsed) + })) } func TestCloneEqual(t *testing.T) {