| 2681 | } |
| 2682 | |
| 2683 | func TestParserRecursionLimit(t *testing.T) { |
| 2684 | testCases := []struct { |
| 2685 | expr string |
| 2686 | errorSubstr string |
| 2687 | out ref.Val |
| 2688 | }{ |
| 2689 | { |
| 2690 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11`, |
| 2691 | errorSubstr: "max recursion depth exceeded", |
| 2692 | }, |
| 2693 | { |
| 2694 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10`, |
| 2695 | out: types.Int(55), |
| 2696 | }, |
| 2697 | { |
| 2698 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 == 45`, |
| 2699 | errorSubstr: "max recursion depth exceeded", |
| 2700 | }, |
| 2701 | { |
| 2702 | // Operator precedence means that '==' is the root. |
| 2703 | expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 == 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9`, |
| 2704 | out: types.True, |
| 2705 | }, |
| 2706 | } |
| 2707 | for _, tc := range testCases { |
| 2708 | tc := tc |
| 2709 | t.Run(tc.expr, func(t *testing.T) { |
| 2710 | env := testEnv(t, ParserRecursionLimit(10)) |
| 2711 | out, err := interpret(t, env, |
| 2712 | tc.expr, map[string]any{}) |
| 2713 | |
| 2714 | if tc.errorSubstr != "" { |
| 2715 | if err == nil || !strings.Contains(err.Error(), tc.errorSubstr) { |
| 2716 | t.Fatalf("prg.Eval() wanted error containing '%s' got %v", tc.errorSubstr, err) |
| 2717 | } |
| 2718 | } |
| 2719 | |
| 2720 | if tc.out != nil { |
| 2721 | if tc.out != out { |
| 2722 | t.Errorf("prg.Eval() wanted %v got %v", tc.out, out) |
| 2723 | } |
| 2724 | } |
| 2725 | }) |
| 2726 | |
| 2727 | } |
| 2728 | } |
| 2729 | |
| 2730 | func TestQuotedFields(t *testing.T) { |
| 2731 | testCases := []struct { |