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

Function TestParserRecursionLimit

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

Source from the content-addressed store, hash-verified

3098}
3099
3100func 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
3147func TestQuotedFields(t *testing.T) {
3148 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