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

Function TestIsLocalVariableNested

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

Source from the content-addressed store, hash-verified

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