MCPcopy
hub / github.com/expr-lang/expr / TestEnv_keyword_with_custom_functions

Function TestEnv_keyword_with_custom_functions

expr_test.go:2295–2319  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2293}
2294
2295func TestEnv_keyword_with_custom_functions(t *testing.T) {
2296 fn := expr.Function("fn", func(params ...any) (any, error) {
2297 return "ok", nil
2298 })
2299
2300 var tests = []struct {
2301 code string
2302 error bool
2303 }{
2304 {`fn()`, false},
2305 {`$env.fn()`, true},
2306 {`$env["fn"]`, true},
2307 }
2308
2309 for _, tt := range tests {
2310 t.Run(tt.code, func(t *testing.T) {
2311 _, err := expr.Compile(tt.code, expr.Env(mock.Env{}), fn)
2312 if tt.error {
2313 require.Error(t, err)
2314 } else {
2315 require.NoError(t, err)
2316 }
2317 })
2318 }
2319}
2320
2321func TestIssue401(t *testing.T) {
2322 program, err := expr.Compile("(a - b + c) / d", expr.AllowUndefinedVariables())

Callers

nothing calls this directly

Calls 6

FunctionFunction · 0.92
CompileFunction · 0.92
EnvStruct · 0.92
ErrorFunction · 0.92
NoErrorFunction · 0.92
RunMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…