diff --git a/t_funcs_test.go b/t_funcs_test.go index 91e4224..95492af 100644 --- a/t_funcs_test.go +++ b/t_funcs_test.go @@ -68,3 +68,27 @@ func TestFunctionGetFunc(t *testing.T) { 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) + +}