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

Function TestLazyVariableResolution

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

Source from the content-addressed store, hash-verified

494}
495
496func TestLazyVariableResolution(t *testing.T) {
497 lazyRefValCalled := 0
498 lazyAnyCalled := 0
499
500 vars := map[string]any{
501 "lazy_ref": func() ref.Val {
502 lazyRefValCalled++
503 return types.IntOne
504 },
505 "lazy_any": func() any {
506 lazyAnyCalled++
507 return 2
508 },
509 "normal": 3,
510 }
511
512 frame := mustNewExecutionFrame(t, vars)
513 defer frame.Close()
514
515 tests := []struct {
516 name string
517 lookupName string
518 wantFound bool
519 wantVal any
520 wantRefCall int
521 wantAnyCall int
522 }{
523 {
524 name: "missing variable",
525 lookupName: "missing",
526 wantFound: false,
527 },
528 {
529 name: "normal variable",
530 lookupName: "normal",
531 wantFound: true,
532 wantVal: 3,
533 },
534 {
535 name: "lazy ref.Val first call",
536 lookupName: "lazy_ref",
537 wantFound: true,
538 wantVal: types.IntOne,
539 wantRefCall: 1,
540 },
541 {
542 name: "lazy ref.Val second call cached",
543 lookupName: "lazy_ref",
544 wantFound: true,
545 wantVal: types.IntOne,
546 wantRefCall: 1,
547 },
548 {
549 name: "lazy any first call",
550 lookupName: "lazy_any",
551 wantFound: true,
552 wantVal: 2,
553 wantRefCall: 1,

Callers

nothing calls this directly

Calls 3

mustNewExecutionFrameFunction · 0.85
CloseMethod · 0.80
ResolveNameMethod · 0.65

Tested by

no test coverage detected