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

Function TestIsLocalVariableNested

interpreter/activation_test.go:134–185  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

132}
133
134func TestIsLocalVariableNested(t *testing.T) {
135 parentAct := EmptyActivation()
136 frame := mustNewExecutionFrame(t, parentAct)
137 defer frame.Close()
138
139 // Outer comprehension scope (e.g. fold1)
140 fold1 := &evalFold{
141 accuVar: "accu1",
142 iterVar: "iter1",
143 iterVar2: "iter1_2",
144 }
145 fld1 := newFolder(fold1, frame)
146 defer releaseFolder(fld1)
147
148 // Push outer scope
149 frame1 := frame.Push(fld1)
150 defer frame1.Pop()
151
152 // Inner comprehension scope (e.g. fold2)
153 fold2 := &evalFold{
154 accuVar: "accu2",
155 iterVar: "iter2",
156 }
157 fld2 := newFolder(fold2, frame1)
158 defer releaseFolder(fld2)
159
160 // Push inner scope
161 frame2 := frame1.Push(fld2)
162 defer frame2.Pop()
163
164 // Verify localVariableHolder implementations and recursive checks
165 tests := []struct {
166 name string
167 varName string
168 wantLocal bool
169 }{
170 {"inner accu", "accu2", true},
171 {"inner iter", "iter2", true},
172 {"outer accu", "accu1", true},
173 {"outer iter", "iter1", true},
174 {"outer iter2", "iter1_2", true},
175 {"global var", "x", false},
176 }
177
178 for _, tc := range tests {
179 t.Run(tc.name, func(t *testing.T) {
180 if got := frame2.IsLocalVariable(tc.varName); got != tc.wantLocal {
181 t.Errorf("IsLocalVariable(%q) = %t, wanted %t", tc.varName, got, tc.wantLocal)
182 }
183 })
184 }
185}
186
187func TestActivation_NewActivationNilInput(t *testing.T) {
188 if _, err := NewActivation(nil); err == nil {

Callers

nothing calls this directly

Calls 8

EmptyActivationFunction · 0.85
mustNewExecutionFrameFunction · 0.85
newFolderFunction · 0.85
releaseFolderFunction · 0.85
CloseMethod · 0.80
IsLocalVariableMethod · 0.65
PushMethod · 0.45
PopMethod · 0.45

Tested by

no test coverage detected