sprinkle in some PBT
All checks were successful
Go / test (push) Successful in 3s

This commit is contained in:
Adam Jeniski 2025-11-05 06:43:24 -10:00
parent f816fdc912
commit ca2485b725

View File

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