(t *testing.T)
| 919 | } |
| 920 | |
| 921 | func TestAttributeStateTracking(t *testing.T) { |
| 922 | var tests = []struct { |
| 923 | expr string |
| 924 | vars []*decls.VariableDecl |
| 925 | in any |
| 926 | out ref.Val |
| 927 | attrs []*AttributePattern |
| 928 | state map[int64]any |
| 929 | }{ |
| 930 | { |
| 931 | expr: `[{"field": true}][0].field`, |
| 932 | vars: []*decls.VariableDecl{}, |
| 933 | in: map[string]any{}, |
| 934 | out: types.True, |
| 935 | state: map[int64]any{ |
| 936 | // [{"field": true}] |
| 937 | 1: []ref.Val{types.DefaultTypeAdapter.NativeToValue(map[ref.Val]ref.Val{types.String("field"): types.True})}, |
| 938 | // [{"field": true}][0] |
| 939 | 6: map[ref.Val]ref.Val{types.String("field"): types.True}, |
| 940 | // [{"field": true}][0].field |
| 941 | 8: true, |
| 942 | }, |
| 943 | }, |
| 944 | { |
| 945 | expr: `a[1]['two']`, |
| 946 | vars: []*decls.VariableDecl{ |
| 947 | decls.NewVariable("a", types.NewMapType( |
| 948 | types.IntType, |
| 949 | types.NewMapType(types.StringType, types.BoolType))), |
| 950 | }, |
| 951 | in: map[string]any{ |
| 952 | "a": map[int64]any{ |
| 953 | 1: map[string]bool{ |
| 954 | "two": true, |
| 955 | }, |
| 956 | }, |
| 957 | }, |
| 958 | out: types.True, |
| 959 | state: map[int64]any{ |
| 960 | // a[1] |
| 961 | 2: map[string]bool{"two": true}, |
| 962 | // a[1]["two"] |
| 963 | 4: true, |
| 964 | }, |
| 965 | }, |
| 966 | { |
| 967 | expr: `a[1][2][3]`, |
| 968 | vars: []*decls.VariableDecl{ |
| 969 | decls.NewVariable("a", types.NewMapType( |
| 970 | types.IntType, |
| 971 | types.NewMapType(types.DynType, types.DynType))), |
| 972 | }, |
| 973 | in: map[string]any{ |
| 974 | "a": map[int64]any{ |
| 975 | 1: map[int64]any{ |
| 976 | 1: 0, |
| 977 | 2: []string{"index", "middex", "outdex", "dex"}, |
| 978 | }, |
nothing calls this directly
no test coverage detected