government / src / eval / function_test.go

@ c491ab51ca7fcb046a61286346455e3aaca25ae3 | history


package eval

import (
	"testing"

	"government/sexpr"
)

// Closures and builtins live in this package, so it must be able to define
// sexpr.Function implementations.
type stubFunc struct {
	sexpr.FunctionBase
	name string
}

func (f stubFunc) Builtin() bool { return true }
func (f stubFunc) Name() string  { return f.name }

func TestEvalCanDefineFunctions(t *testing.T) {
	var v sexpr.Value = stubFunc{name: "+"}
	if _, ok := v.(sexpr.Function); !ok {
		t.Fatal("stubFunc is not a sexpr.Function")
	}
	if got := sexpr.Print(v); got != "#<builtin +>" {
		t.Errorf("Print = %s, want #<builtin +>", got)
	}
}