Compare commits
No commits in common. "ca2485b725205dd0366cce4b04481a4708e7c348" and "465c959414c554b6696805620799db8c0c87b343" have entirely different histories.
ca2485b725
...
465c959414
@ -49,13 +49,8 @@ func (this *HashMap) Conj(key any, val any) *HashMap {
|
||||
return Conj(this, key, val)
|
||||
}
|
||||
|
||||
func (this *HashMap) IsEmpty() bool {
|
||||
return len(this._map) == 0
|
||||
|
||||
}
|
||||
|
||||
func (this *HashMap) String() string {
|
||||
if this.IsEmpty() {
|
||||
func String(this *HashMap) string {
|
||||
if this == nil {
|
||||
return "{}"
|
||||
}
|
||||
var sb strings.Builder
|
||||
@ -68,5 +63,8 @@ func (this *HashMap) String() string {
|
||||
sb.WriteRune(' ')
|
||||
}
|
||||
return sb.String()[:sb.Len()-2] + "}"
|
||||
|
||||
}
|
||||
|
||||
func (this *HashMap) String() string {
|
||||
return String(this)
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package read
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mal-go/hash_map"
|
||||
"mal-go/symbol"
|
||||
"mal-go/vector"
|
||||
@ -48,8 +47,6 @@ func readForm(s string, pos int, ns string) (any, any, int) {
|
||||
res, err, pos = readVector(s, pos, ns)
|
||||
case '(':
|
||||
res, err, pos = readList(s, pos, ns)
|
||||
default:
|
||||
return nil, "unexpected char: '" + fmt.Sprint(c) + "'", pos
|
||||
}
|
||||
}
|
||||
return res, err, pos
|
||||
@ -57,10 +54,7 @@ func readForm(s string, pos int, ns string) (any, any, int) {
|
||||
|
||||
func readMap(s string, pos int, ns string) (any, any, int) {
|
||||
m := hash_map.New()
|
||||
if s[pos+1] == '}' {
|
||||
return m, nil, pos + 2
|
||||
}
|
||||
return nil, "unimplemented", pos
|
||||
return m, "unimplemented", pos
|
||||
}
|
||||
|
||||
func readList(s string, pos int, ns string) (any, any, int) {
|
||||
|
||||
@ -1,15 +1,10 @@
|
||||
package read
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mal-go/hash_map"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"mal-go/list"
|
||||
"mal-go/symbol"
|
||||
"mal-go/vector"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"pgregory.net/rapid"
|
||||
)
|
||||
|
||||
func TestReadInt(t *testing.T) {
|
||||
@ -52,33 +47,3 @@ 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)
|
||||
})
|
||||
}
|
||||
|
||||
@ -30,8 +30,8 @@ func (this *Vector) Conj(data any) *Vector {
|
||||
return newVec
|
||||
}
|
||||
|
||||
func (this *Vector) String() string {
|
||||
if this.IsEmpty() {
|
||||
func String(this *Vector) string {
|
||||
if this == nil {
|
||||
return "[]"
|
||||
}
|
||||
var sb strings.Builder
|
||||
@ -41,11 +41,10 @@ func (this *Vector) String() string {
|
||||
sb.WriteRune(' ')
|
||||
}
|
||||
return sb.String()[:sb.Len()-1] + "]"
|
||||
|
||||
}
|
||||
|
||||
func (this *Vector) IsEmpty() bool {
|
||||
return len(this._slice) == 0
|
||||
func (this *Vector) String() string {
|
||||
return String(this)
|
||||
}
|
||||
|
||||
func ToList(this *Vector) list.IList {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user