(t *testing.T)
| 1111 | } |
| 1112 | |
| 1113 | func TestAttributeStateTracking(t *testing.T) { |
| 1114 | var tests = []struct { |
| 1115 | expr string |
| 1116 | vars []*decls.VariableDecl |
| 1117 | in any |
| 1118 | out ref.Val |
| 1119 | attrs []*AttributePattern |
| 1120 | state map[int64]any |
| 1121 | }{ |
| 1122 | { |
| 1123 | expr: `[{"field": true}][0].field`, |
| 1124 | vars: []*decls.VariableDecl{}, |
| 1125 | in: map[string]any{}, |
| 1126 | out: types.True, |
| 1127 | state: map[int64]any{ |
| 1128 | // [{"field": true}] |
| 1129 | 1: []ref.Val{types.DefaultTypeAdapter.NativeToValue(map[ref.Val]ref.Val{types.String("field"): types.True})}, |
| 1130 | // [{"field": true}][0] |
| 1131 | 6: map[ref.Val]ref.Val{types.String("field"): types.True}, |
| 1132 | // [{"field": true}][0].field |
| 1133 | 8: true, |
| 1134 | }, |
| 1135 | }, |
| 1136 | { |
| 1137 | expr: `a[1]['two']`, |
| 1138 | vars: []*decls.VariableDecl{ |
| 1139 | decls.NewVariable("a", types.NewMapType( |
| 1140 | types.IntType, |
| 1141 | types.NewMapType(types.StringType, types.BoolType))), |
| 1142 | }, |
| 1143 | in: map[string]any{ |
| 1144 | "a": map[int64]any{ |
| 1145 | 1: map[string]bool{ |
| 1146 | "two": true, |
| 1147 | }, |
| 1148 | }, |
| 1149 | }, |
| 1150 | out: types.True, |
| 1151 | state: map[int64]any{ |
| 1152 | // a[1] |
| 1153 | 2: map[string]bool{"two": true}, |
| 1154 | // a[1]["two"] |
| 1155 | 4: true, |
| 1156 | }, |
| 1157 | }, |
| 1158 | { |
| 1159 | expr: `a[1][2][3]`, |
| 1160 | vars: []*decls.VariableDecl{ |
| 1161 | decls.NewVariable("a", types.NewMapType( |
| 1162 | types.IntType, |
| 1163 | types.NewMapType(types.DynType, types.DynType))), |
| 1164 | }, |
| 1165 | in: map[string]any{ |
| 1166 | "a": map[int64]any{ |
| 1167 | 1: map[int64]any{ |
| 1168 | 1: 0, |
| 1169 | 2: []string{"index", "middex", "outdex", "dex"}, |
| 1170 | }, |
nothing calls this directly
no test coverage detected