elvish/newedit/hooks_api_test.go
2019-04-18 22:58:06 +01:00

40 lines
854 B
Go

package newedit
import (
"testing"
"github.com/elves/elvish/eval"
"github.com/elves/elvish/eval/vals"
)
func TestInitBeforeReadline(t *testing.T) {
variable, cb := initBeforeReadline(eval.NewEvaler())
called := 0
variable.Set(vals.EmptyList.Cons(eval.NewGoFn("[test]", func() {
called++
})))
cb()
if called != 1 {
t.Errorf("Called %d times, want once", called)
}
// TODO: Test input and output
}
func TestInitAfterReadline(t *testing.T) {
variable, cb := initAfterReadline(eval.NewEvaler())
called := 0
calledWith := ""
variable.Set(vals.EmptyList.Cons(eval.NewGoFn("[test]", func(s string) {
called++
calledWith = s
})))
cb("code")
if called != 1 {
t.Errorf("Called %d times, want once", called)
}
if calledWith != "code" {
t.Errorf("Called with %q, want %q", calledWith, "code")
}
// TODO: Test input and output
}