(t *testing.T)
| 105 | } |
| 106 | |
| 107 | func 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 | |
| 141 | func TestAttributesRelativeAttrOneOf(t *testing.T) { |
| 142 | reg := newTestRegistry(t) |
nothing calls this directly
no test coverage detected