added TestGoFunction() to test Go functions
This commit is contained in:
parent
518d4d8d65
commit
f8d12b1a93
@ -68,3 +68,27 @@ func TestFunctionGetFunc(t *testing.T) {
|
|||||||
t.Errorf(`(func() -> result = %v [%T], want = %v [%T]`, got, got, want, want)
|
t.Errorf(`(func() -> result = %v [%T], want = %v [%T]`, got, got, want, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGoFunction(t *testing.T) {
|
||||||
|
section := "Funcs"
|
||||||
|
inputs := []inputType{
|
||||||
|
/* 1 */ {`myName()`, "Celestino Amoroso", nil},
|
||||||
|
/* 2 */ {`myName("Peppino")`, "Peppino", nil},
|
||||||
|
}
|
||||||
|
|
||||||
|
myName := func(ctx ExprContext, name string, args map[string]any) (result any, err error) {
|
||||||
|
var ok bool
|
||||||
|
if result, ok = args["name"].(string); !ok {
|
||||||
|
err = ErrWrongParamType(name, "name", TypeString, args["name"])
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := NewSimpleStore()
|
||||||
|
ctx.RegisterFunc("myName", NewGolangFunctor(myName), TypeString, []ExprFuncParam{
|
||||||
|
NewFuncParamFlagDef("name", PfOptional|PfDefault, "Celestino Amoroso"),
|
||||||
|
})
|
||||||
|
|
||||||
|
runCtxTestSuite(t, ctx, section, inputs)
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user