MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestParserRecursionLimit

Function TestParserRecursionLimit

cel/cel_test.go:2703–2748  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2701}
2702
2703func 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
2750func TestQuotedFields(t *testing.T) {
2751 testCases := []struct {

Callers

nothing calls this directly

Calls 6

IntTypeAlias · 0.92
ParserRecursionLimitFunction · 0.85
interpretFunction · 0.85
testEnvFunction · 0.70
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected