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

Function TestAddLetFn

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

Source from the content-addressed store, hash-verified

177}
178
179func TestAddLetFn(t *testing.T) {
180 eval, err := NewEvaluator()
181 if err != nil {
182 t.Fatalf("NewEvaluator() failed with: %v", err)
183 }
184
185 err = eval.AddLetFn("fn", []letFunctionParam{
186 {identifier: "x", typeHint: mustParseType(t, "int")},
187 {identifier: "y", typeHint: mustParseType(t, "int")}},
188 mustParseType(t, "int"),
189 "x * x - y * y")
190 if err != nil {
191 t.Fatalf("AddLetFn{fn(x: int, y: int): int -> x * x - y * y} = (err) %v", err)
192 }
193
194 eval.AddLetVar("testcases", "[[1, 2], [2, 3], [3, 4], [10, 20]]", mustParseType(t, "list<list<int>>"))
195
196 result, _, err := eval.Evaluate("testcases.all(e, fn(e[0], e[1]) == (e[0] - e[1]) * (e[0] + e[1]))")
197
198 if err != nil {
199 t.Errorf("eval.Evaluate() got error %v wanted nil", err)
200 } else if !result.Value().(bool) {
201 t.Errorf("eval.Evaluate() got %v wanted true", result.Value())
202 }
203}
204
205func TestAddLetFnComposed(t *testing.T) {
206 eval, err := NewEvaluator()

Callers

nothing calls this directly

Calls 6

AddLetFnMethod · 0.95
AddLetVarMethod · 0.95
EvaluateMethod · 0.95
NewEvaluatorFunction · 0.85
mustParseTypeFunction · 0.85
ValueMethod · 0.65

Tested by

no test coverage detected