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

Function TestInstanceFunction

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

Source from the content-addressed store, hash-verified

416}
417
418func TestInstanceFunction(t *testing.T) {
419 eval, err := NewEvaluator()
420 if err != nil {
421 t.Fatalf("NewEvaluator() failed with: %v", err)
422 }
423
424 err = eval.AddLetFn("int.plus", []letFunctionParam{
425 {identifier: "y", typeHint: mustParseType(t, "int")}},
426 mustParseType(t, "int"),
427 "this + y")
428
429 if err != nil {
430 t.Fatalf("eval.AddLetFn('int.plus(y : int): int -> this + y') failed: %s", err)
431 }
432
433 val, _, err := eval.Evaluate("40.plus(2)")
434 if err != nil {
435 t.Errorf("eval.Eval('40.plus(2)') got error %v, wanted nil", err)
436 }
437 if val.Value().(int64) != 42 {
438 t.Errorf("eval.Eval('40.plus(2)') got %s, wanted 42", val)
439 }
440}
441
442type testContainerOption struct {
443 container string

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected