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

Function TestParserRecursionLimit

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

Source from the content-addressed store, hash-verified

2681}
2682
2683func 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
2730func TestQuotedFields(t *testing.T) {
2731 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