Test more Parse failures

This commit is contained in:
Brandon Dyck 2024-09-18 11:46:39 -06:00
parent c770c1ca8b
commit 4a13ec209d

View File

@ -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) {