| 3098 | } |
| 3099 | |
| 3100 | func TestParserRecursionLimit(t *testing.T) { |
| 3101 | testCases := []struct { |
| 3102 | expr string |
| 3103 | errorSubstr string |
| 3104 | out ref.Val |
| 3105 | }{ |
| 3106 | { |
| 3107 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11`, |
| 3108 | errorSubstr: "max recursion depth exceeded", |
| 3109 | }, |
| 3110 | { |
| 3111 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10`, |
| 3112 | out: types.Int(55), |
| 3113 | }, |
| 3114 | { |
| 3115 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 == 45`, |
| 3116 | errorSubstr: "max recursion depth exceeded", |
| 3117 | }, |
| 3118 | { |
| 3119 | // Operator precedence means that '==' is the root. |
| 3120 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 == 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9`, |
| 3121 | out: types.True, |
| 3122 | }, |
| 3123 | } |
| 3124 | for _, tc := range testCases { |
| 3125 | tc := tc |
| 3126 | t.Run(tc.expr, func(t *testing.T) { |
| 3127 | env := testEnv(t, ParserRecursionLimit(10)) |
| 3128 | out, err := interpret(t, env, |
| 3129 | tc.expr, map[string]any{}) |
| 3130 | |
| 3131 | if tc.errorSubstr != "" { |
| 3132 | if err == nil || !strings.Contains(err.Error(), tc.errorSubstr) { |
| 3133 | t.Fatalf("prg.Eval() wanted error containing '%s' got %v", tc.errorSubstr, err) |
| 3134 | } |
| 3135 | } |
| 3136 | |
| 3137 | if tc.out != nil { |
| 3138 | if tc.out != out { |
| 3139 | t.Errorf("prg.Eval() wanted %v got %v", tc.out, out) |
| 3140 | } |
| 3141 | } |
| 3142 | }) |
| 3143 | |
| 3144 | } |
| 3145 | } |
| 3146 | |
| 3147 | func TestQuotedFields(t *testing.T) { |
| 3148 | testCases := []struct { |