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

Function TestParserRecursionLimit

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

Source from the content-addressed store, hash-verified

2896}
2897
2898func TestParserRecursionLimit(t *testing.T) {
2899 testCases := []struct {
2900 expr string
2901 errorSubstr string
2902 out ref.Val
2903 }{
2904 {
2905 expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11`,
2906 errorSubstr: "max recursion depth exceeded",
2907 },
2908 {
2909 expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10`,
2910 out: types.Int(55),
2911 },
2912 {
2913 expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 == 45`,
2914 errorSubstr: "max recursion depth exceeded",
2915 },
2916 {
2917 // Operator precedence means that '==' is the root.
2918 expr: `0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 == 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9`,
2919 out: types.True,
2920 },
2921 }
2922 for _, tc := range testCases {
2923 tc := tc
2924 t.Run(tc.expr, func(t *testing.T) {
2925 env := testEnv(t, ParserRecursionLimit(10))
2926 out, err := interpret(t, env,
2927 tc.expr, map[string]any{})
2928
2929 if tc.errorSubstr != "" {
2930 if err == nil || !strings.Contains(err.Error(), tc.errorSubstr) {
2931 t.Fatalf("prg.Eval() wanted error containing '%s' got %v", tc.errorSubstr, err)
2932 }
2933 }
2934
2935 if tc.out != nil {
2936 if tc.out != out {
2937 t.Errorf("prg.Eval() wanted %v got %v", tc.out, out)
2938 }
2939 }
2940 })
2941
2942 }
2943}
2944
2945func TestQuotedFields(t *testing.T) {
2946 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