| 2954 | } |
| 2955 | |
| 2956 | func TestParserRecursionLimit(t *testing.T) { |
| 2957 | testCases := []struct { |
| 2958 | expr string |
| 2959 | errorSubstr string |
| 2960 | out ref.Val |
| 2961 | }{ |
| 2962 | { |
| 2963 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11`, |
| 2964 | errorSubstr: "max recursion depth exceeded", |
| 2965 | }, |
| 2966 | { |
| 2967 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10`, |
| 2968 | out: types.Int(55), |
| 2969 | }, |
| 2970 | { |
| 2971 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 == 45`, |
| 2972 | errorSubstr: "max recursion depth exceeded", |
| 2973 | }, |
| 2974 | { |
| 2975 | // Operator precedence means that '==' is the root. |
| 2976 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 == 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9`, |
| 2977 | out: types.True, |
| 2978 | }, |
| 2979 | } |
| 2980 | for _, tc := range testCases { |
| 2981 | tc := tc |
| 2982 | t.Run(tc.expr, func(t *testing.T) { |
| 2983 | env := testEnv(t, ParserRecursionLimit(10)) |
| 2984 | out, err := interpret(t, env, |
| 2985 | tc.expr, map[string]any{}) |
| 2986 | |
| 2987 | if tc.errorSubstr != "" { |
| 2988 | if err == nil || !strings.Contains(err.Error(), tc.errorSubstr) { |
| 2989 | t.Fatalf("prg.Eval() wanted error containing '%s' got %v", tc.errorSubstr, err) |
| 2990 | } |
| 2991 | } |
| 2992 | |
| 2993 | if tc.out != nil { |
| 2994 | if tc.out != out { |
| 2995 | t.Errorf("prg.Eval() wanted %v got %v", tc.out, out) |
| 2996 | } |
| 2997 | } |
| 2998 | }) |
| 2999 | |
| 3000 | } |
| 3001 | } |
| 3002 | |
| 3003 | func TestQuotedFields(t *testing.T) { |
| 3004 | testCases := []struct { |