(t *testing.T)
| 2943 | } |
| 2944 | |
| 2945 | func TestQuotedFields(t *testing.T) { |
| 2946 | testCases := []struct { |
| 2947 | expr string |
| 2948 | errorSubstr string |
| 2949 | out ref.Val |
| 2950 | }{ |
| 2951 | { |
| 2952 | expr: "{'key-1': 64}.`key-1`", |
| 2953 | out: types.Int(64), |
| 2954 | }, |
| 2955 | { |
| 2956 | expr: "{'key-1': 64}.`key-2`", |
| 2957 | errorSubstr: "no such key: key-2", |
| 2958 | }, |
| 2959 | { |
| 2960 | expr: "has({'key-1': 64}.`key-1`)", |
| 2961 | out: types.True, |
| 2962 | }, |
| 2963 | { |
| 2964 | expr: "has({'key-1': 64}.`key-2`)", |
| 2965 | out: types.False, |
| 2966 | }, |
| 2967 | } |
| 2968 | for _, tc := range testCases { |
| 2969 | tc := tc |
| 2970 | t.Run(tc.expr, func(t *testing.T) { |
| 2971 | env := testEnv(t, ParserRecursionLimit(10), |
| 2972 | EnableIdentifierEscapeSyntax()) |
| 2973 | out, err := interpret(t, env, |
| 2974 | tc.expr, map[string]any{}) |
| 2975 | |
| 2976 | if tc.errorSubstr != "" { |
| 2977 | if err == nil || !strings.Contains(err.Error(), tc.errorSubstr) { |
| 2978 | t.Fatalf("prg.Eval() wanted error containing '%s' got %v", tc.errorSubstr, err) |
| 2979 | } |
| 2980 | } |
| 2981 | |
| 2982 | if tc.out != nil { |
| 2983 | if tc.out != out { |
| 2984 | t.Errorf("prg.Eval() wanted %v got %v", tc.out, out) |
| 2985 | } |
| 2986 | } |
| 2987 | }) |
| 2988 | |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | func TestDynamicDispatch(t *testing.T) { |
| 2993 | env := testEnv(t, |
nothing calls this directly
no test coverage detected