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

Function TestAttributeStateTracking

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

Source from the content-addressed store, hash-verified

919}
920
921func 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 },

Callers

nothing calls this directly

Calls 15

ParseMethod · 0.95
AddFunctionsMethod · 0.95
AddIdentsMethod · 0.95
EvalMethod · 0.95
StringTypeAlias · 0.92
NewVariableFunction · 0.92
NewMapTypeFunction · 0.92
NewListTypeFunction · 0.92
IntTypeAlias · 0.92
OptionalOfFunction · 0.92
NewUnknownFunction · 0.92
NewAttributeTrailFunction · 0.92

Tested by

no test coverage detected