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

Function TestAttributesRelativeAttr

interpreter/attributes_test.go:107–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

105}
106
107func TestAttributesRelativeAttr(t *testing.T) {
108 reg := newTestRegistry(t)
109 attrs := NewAttributeFactory(containers.DefaultContainer, reg, reg)
110 data := map[string]any{
111 "a": map[int]any{
112 -1: []int32{2, 42},
113 },
114 "b": 1,
115 }
116 vars, _ := NewActivation(data)
117
118 // The relative attribute under test is applied to a map literal:
119 // {
120 // a: {-1: [2, 42], b: 1}
121 // b: 1
122 // }
123 //
124 // The expression being evaluated is: <map-literal>.a[-1][b] -> 42
125 op := NewConstValue(1, reg.NativeToValue(data))
126 attr := attrs.RelativeAttribute(1, op)
127 qualA := makeQualifier(t, attrs, nil, 2, "a")
128 qualNeg1 := makeQualifier(t, attrs, nil, 3, int64(-1))
129 attr.AddQualifier(qualA)
130 attr.AddQualifier(qualNeg1)
131 attr.AddQualifier(attrs.AbsoluteAttribute(4, "b"))
132 out, err := attr.Resolve(vars)
133 if err != nil {
134 t.Fatal(err)
135 }
136 if out != types.Int(42) {
137 t.Errorf("Got %v (%T), wanted 42", out, out)
138 }
139}
140
141func TestAttributesRelativeAttrOneOf(t *testing.T) {
142 reg := newTestRegistry(t)

Callers

nothing calls this directly

Calls 11

RelativeAttributeMethod · 0.95
AbsoluteAttributeMethod · 0.95
IntTypeAlias · 0.92
NewAttributeFactoryFunction · 0.85
NewConstValueFunction · 0.85
makeQualifierFunction · 0.85
newTestRegistryFunction · 0.70
NewActivationFunction · 0.70
NativeToValueMethod · 0.65
AddQualifierMethod · 0.65
ResolveMethod · 0.65

Tested by

no test coverage detected