| 2896 | } |
| 2897 | |
| 2898 | func TestParserRecursionLimit(t *testing.T) { |
| 2899 | testCases := []struct { |
| 2900 | expr string |
| 2901 | errorSubstr string |
| 2902 | out ref.Val |
| 2903 | }{ |
| 2904 | { |
| 2905 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11`, |
| 2906 | errorSubstr: "max recursion depth exceeded", |
| 2907 | }, |
| 2908 | { |
| 2909 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10`, |
| 2910 | out: types.Int(55), |
| 2911 | }, |
| 2912 | { |
| 2913 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 == 45`, |
| 2914 | errorSubstr: "max recursion depth exceeded", |
| 2915 | }, |
| 2916 | { |
| 2917 | // Operator precedence means that '==' is the root. |
| 2918 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 == 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9`, |
| 2919 | out: types.True, |
| 2920 | }, |
| 2921 | } |
| 2922 | for _, tc := range testCases { |
| 2923 | tc := tc |
| 2924 | t.Run(tc.expr, func(t *testing.T) { |
| 2925 | env := testEnv(t, ParserRecursionLimit(10)) |
| 2926 | out, err := interpret(t, env, |
| 2927 | tc.expr, map[string]any{}) |
| 2928 | |
| 2929 | if tc.errorSubstr != "" { |
| 2930 | if err == nil || !strings.Contains(err.Error(), tc.errorSubstr) { |
| 2931 | t.Fatalf("prg.Eval() wanted error containing '%s' got %v", tc.errorSubstr, err) |
| 2932 | } |
| 2933 | } |
| 2934 | |
| 2935 | if tc.out != nil { |
| 2936 | if tc.out != out { |
| 2937 | t.Errorf("prg.Eval() wanted %v got %v", tc.out, out) |
| 2938 | } |
| 2939 | } |
| 2940 | }) |
| 2941 | |
| 2942 | } |
| 2943 | } |
| 2944 | |
| 2945 | func TestQuotedFields(t *testing.T) { |
| 2946 | testCases := []struct { |