ginger/eval/eval_test.go

42 lines
902 B
Go
Raw Normal View History

2014-10-21 04:06:49 +00:00
package eval
import (
. "testing"
"github.com/mediocregopher/ginger/core"
2014-10-21 04:06:49 +00:00
"github.com/mediocregopher/ginger/macros/pkgctx"
"github.com/mediocregopher/ginger/parse"
"github.com/mediocregopher/ginger/types"
)
// This is NOT how I want eval to really work in the end, but I wanted to get
// something down before I kept thinking about it, so I would know what would
// work
func TestShittyPlus(t *T) {
p := &pkgctx.PkgCtx{
CallMap: map[string]interface{}{
"Plus": Evaler(core.Plus),
2014-10-21 04:06:49 +00:00
},
}
m := map[string]types.Elem{
"(: Plus)": types.GoType{0},
"(: Plus 1 2 3)": types.GoType{6},
`(: Plus 1 2 3
(: Plus 1 2 3))`: types.GoType{12},
2014-10-21 04:06:49 +00:00
}
for input, output := range m {
parsed, err := parse.ParseString(input)
if err != nil {
t.Fatal(err)
}
evald := Eval(p, parsed)
if !evald.Equal(output) {
t.Fatalf("input: %q %#v != %#v", input, output, evald)
}
}
}