MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestAddDeclFn

Function TestAddDeclFn

repl/evaluator_test.go:312–332  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

310}
311
312func TestAddDeclFn(t *testing.T) {
313 eval, err := NewEvaluator()
314 if err != nil {
315 t.Fatalf("NewEvaluator() failed with: %v", err)
316 }
317
318 err = eval.AddDeclFn("fn", []letFunctionParam{
319 {identifier: "x", typeHint: mustParseType(t, "int")},
320 {identifier: "y", typeHint: mustParseType(t, "int")}},
321 mustParseType(t, "int"))
322
323 if err != nil {
324 t.Errorf("eval.AddDeclFn('fn(x:int, y:int): int') got error %v wanted nil", err)
325 }
326
327 err = eval.AddLetVar("z", "fn(1, 2)", nil)
328
329 if err != nil {
330 t.Errorf("eval.AddLetVar('z = fn(1, 2)') got error %v wanted nil", err)
331 }
332}
333
334func TestAddDeclFnError(t *testing.T) {
335 eval, err := NewEvaluator()

Callers

nothing calls this directly

Calls 4

AddDeclFnMethod · 0.95
AddLetVarMethod · 0.95
NewEvaluatorFunction · 0.85
mustParseTypeFunction · 0.85

Tested by

no test coverage detected