diff --git a/read/read_test.go b/read/read_test.go index 16e0b93..c448a45 100644 --- a/read/read_test.go +++ b/read/read_test.go @@ -1,10 +1,15 @@ package read import ( - "github.com/stretchr/testify/assert" + "fmt" + "mal-go/hash_map" "mal-go/list" "mal-go/symbol" + "mal-go/vector" "testing" + + "github.com/stretchr/testify/assert" + "pgregory.net/rapid" ) func TestReadInt(t *testing.T) { @@ -47,3 +52,33 @@ func TestReadList(t *testing.T) { assert.Equal(t, nil, err, "should read without error") assert.Equal(t, len(input), pos, "should read the whole string") } + +func StringifiedFormGen() *rapid.Generator[string] { + return rapid.OneOf(rapid.Custom(func(t *rapid.T) string { + myList := list.Empty() + i := 200 + t.Repeat(map[string]func(*rapid.T){ + "conj": func(t *rapid.T) { + if i < 50 { + myList = myList.Conj(StringifiedFormGen().Draw(t, "el")) + } + }, + }) + return myList.String() + }), + rapid.Just(list.Empty().String()), + rapid.Just(hash_map.New().String()), + rapid.Just(vector.New().String()), + rapid.Custom(func(t *rapid.T) string { + return fmt.Sprint(rapid.Int().Draw(t, "i")) + }), + ) +} + +func TestRead(t *testing.T) { + rapid.Check(t, func(t *rapid.T) { + input := StringifiedFormGen().Draw(t, "input") + _, err, _ := readForm(input, 0, "user") + assert.Nil(t, err, err) + }) +}