| 2701 | } |
| 2702 | |
| 2703 | func TestParserRecursionLimit(t *testing.T) { |
| 2704 | testCases := []struct { |
| 2705 | expr string |
| 2706 | errorSubstr string |
| 2707 | out ref.Val |
| 2708 | }{ |
| 2709 | { |
| 2710 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11`, |
| 2711 | errorSubstr: "max recursion depth exceeded", |
| 2712 | }, |
| 2713 | { |
| 2714 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10`, |
| 2715 | out: types.Int(55), |
| 2716 | }, |
| 2717 | { |
| 2718 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 == 45`, |
| 2719 | errorSubstr: "max recursion depth exceeded", |
| 2720 | }, |
| 2721 | { |
| 2722 | // Operator precedence means that '==' is the root. |
| 2723 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 == 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9`, |
| 2724 | out: types.True, |
| 2725 | }, |
| 2726 | } |
| 2727 | for _, tc := range testCases { |
| 2728 | tc := tc |
| 2729 | t.Run(tc.expr, func(t *testing.T) { |
| 2730 | env := testEnv(t, ParserRecursionLimit(10)) |
| 2731 | out, err := interpret(t, env, |
| 2732 | tc.expr, map[string]any{}) |
| 2733 | |
| 2734 | if tc.errorSubstr != "" { |
| 2735 | if err == nil || !strings.Contains(err.Error(), tc.errorSubstr) { |
| 2736 | t.Fatalf("prg.Eval() wanted error containing '%s' got %v", tc.errorSubstr, err) |
| 2737 | } |
| 2738 | } |
| 2739 | |
| 2740 | if tc.out != nil { |
| 2741 | if tc.out != out { |
| 2742 | t.Errorf("prg.Eval() wanted %v got %v", tc.out, out) |
| 2743 | } |
| 2744 | } |
| 2745 | }) |
| 2746 | |
| 2747 | } |
| 2748 | } |
| 2749 | |
| 2750 | func TestQuotedFields(t *testing.T) { |
| 2751 | testCases := []struct { |