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

Function TestLazyVariableResolution

interpreter/frame_test.go:622–711  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

620}
621
622func TestLazyVariableResolution(t *testing.T) {
623 lazyRefValCalled := 0
624 lazyAnyCalled := 0
625
626 vars := map[string]any{
627 "lazy_ref": func() ref.Val {
628 lazyRefValCalled++
629 return types.IntOne
630 },
631 "lazy_any": func() any {
632 lazyAnyCalled++
633 return 2
634 },
635 "normal": 3,
636 }
637
638 frame := mustNewExecutionFrame(t, vars)
639 defer frame.Close()
640
641 tests := []struct {
642 name string
643 lookupName string
644 wantFound bool
645 wantVal any
646 wantRefCall int
647 wantAnyCall int
648 }{
649 {
650 name: "missing variable",
651 lookupName: "missing",
652 wantFound: false,
653 },
654 {
655 name: "normal variable",
656 lookupName: "normal",
657 wantFound: true,
658 wantVal: 3,
659 },
660 {
661 name: "lazy ref.Val first call",
662 lookupName: "lazy_ref",
663 wantFound: true,
664 wantVal: types.IntOne,
665 wantRefCall: 1,
666 },
667 {
668 name: "lazy ref.Val second call cached",
669 lookupName: "lazy_ref",
670 wantFound: true,
671 wantVal: types.IntOne,
672 wantRefCall: 1,
673 },
674 {
675 name: "lazy any first call",
676 lookupName: "lazy_any",
677 wantFound: true,
678 wantVal: 2,
679 wantRefCall: 1,

Callers

nothing calls this directly

Calls 3

mustNewExecutionFrameFunction · 0.85
CloseMethod · 0.80
ResolveNameMethod · 0.65

Tested by

no test coverage detected