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

Function TestMaxExpressionNodeCount

parser/parser_test.go:2925–2942  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2923}
2924
2925func TestMaxExpressionNodeCount(t *testing.T) {
2926 for _, pratt := range []bool{false, true} {
2927 t.Run(fmt.Sprintf("enablePrattParser=%t", pratt), func(t *testing.T) {
2928 p, err := NewParser(Macros(AllMacros...), MaxExpressionNodeCount(10), EnablePrattParser(pratt))
2929 if err != nil {
2930 t.Fatal(err)
2931 }
2932 src := common.NewTextSource("a.exists(x, x.exists(y, y == 1))")
2933 _, errs := p.Parse(src)
2934 if len(errs.GetErrors()) == 0 {
2935 t.Fatalf("expected errors, got none: %s", errs.ToDisplayString())
2936 }
2937 if !strings.Contains(errs.GetErrors()[0].Message, "expression count exceeds limit of 10 while expanding macro 'exists'") {
2938 t.Fatalf("got %q, want substring matching limit error: %s", errs.GetErrors()[0].Message, errs.GetErrors()[0].ToDisplayString(src))
2939 }
2940 })
2941 }
2942}
2943
2944func TestParserOptionErrors(t *testing.T) {
2945 if _, err := NewParser(Macros(AllMacros...), MaxRecursionDepth(-2)); err == nil {

Callers

nothing calls this directly

Calls 9

ParseMethod · 0.95
NewTextSourceFunction · 0.92
MaxExpressionNodeCountFunction · 0.85
EnablePrattParserFunction · 0.85
GetErrorsMethod · 0.80
NewParserFunction · 0.70
MacrosFunction · 0.70
ContainsMethod · 0.65
ToDisplayStringMethod · 0.45

Tested by

no test coverage detected