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

Function TestAttributePattern_LocallyBound

interpreter/attribute_patterns_test.go:340–386  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

338}
339
340func TestAttributePattern_LocallyBound(t *testing.T) {
341 reg := newTestRegistry(t)
342 fac := NewPartialAttributeFactory(containers.DefaultContainer, reg, reg)
343
344 // Create a partial activation that designates "x" and "y" as unknown.
345 partAct, err := NewPartialActivation(EmptyActivation(), NewAttributePattern("x"), NewAttributePattern("y"))
346 if err != nil {
347 t.Fatal(err)
348 }
349
350 frame := mustNewExecutionFrame(t, partAct)
351 defer frame.Close()
352
353 // Create folder (representing a local scope for variable "x" only)
354 fold := &evalFold{
355 iterVar: "x",
356 adapter: types.DefaultTypeAdapter,
357 }
358 fld := newFolder(fold, frame)
359 defer releaseFolder(fld)
360
361 // Push onto the frame stack to simulate local variable scope
362 frame1 := frame.Push(fld)
363 defer frame1.Pop()
364
365 // 1. Resolve attribute matching "x".
366 // Because "x" is locally bound in fld, it should not resolve to types.Unknown.
367 attrX := fac.AbsoluteAttribute(1, "x")
368 valX, err := attrX.Resolve(frame1)
369 if err != nil {
370 t.Fatal(err)
371 }
372 if _, isUnk := valX.(*types.Unknown); isUnk {
373 t.Errorf("Resolve(x) got unknown, wanted value (since x is locally bound)")
374 }
375
376 // 2. Resolve attribute matching "y".
377 // Because "y" is NOT locally bound in any local scope layer, it should resolve to types.Unknown.
378 attrY := fac.AbsoluteAttribute(2, "y")
379 valY, err := attrY.Resolve(frame1)
380 if err != nil {
381 t.Fatal(err)
382 }
383 if _, isUnk := valY.(*types.Unknown); !isUnk {
384 t.Errorf("Resolve(y) got %v, wanted types.Unknown (since y is not locally bound)", valY)
385 }
386}
387
388func TestQualifierValueEquals(t *testing.T) {
389 tests := []struct {

Callers

nothing calls this directly

Calls 13

NewPartialActivationFunction · 0.85
EmptyActivationFunction · 0.85
NewAttributePatternFunction · 0.85
mustNewExecutionFrameFunction · 0.85
newFolderFunction · 0.85
releaseFolderFunction · 0.85
CloseMethod · 0.80
newTestRegistryFunction · 0.70
AbsoluteAttributeMethod · 0.65
ResolveMethod · 0.65
PushMethod · 0.45

Tested by

no test coverage detected