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

Function TestMaxExpressionNodeCount

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

Source from the content-addressed store, hash-verified

2319}
2320
2321func TestMaxExpressionNodeCount(t *testing.T) {
2322 p, err := NewParser(Macros(AllMacros...), MaxExpressionNodeCount(10))
2323 if err != nil {
2324 t.Fatal(err)
2325 }
2326 src := common.NewTextSource("a.exists(x, x.exists(y, y == 1))")
2327 _, errs := p.Parse(src)
2328 if len(errs.GetErrors()) == 0 {
2329 t.Fatalf("expected errors, got none: %s", errs.ToDisplayString())
2330 }
2331 if !strings.Contains(errs.GetErrors()[0].Message, "expression count exceeds limit of 10 while expanding macro 'exists'") {
2332 t.Fatalf("got %q, want substring matching limit error: %s", errs.GetErrors()[0].Message, errs.GetErrors()[0].ToDisplayString(src))
2333 }
2334}
2335
2336func TestParserOptionErrors(t *testing.T) {
2337 if _, err := NewParser(Macros(AllMacros...), MaxRecursionDepth(-2)); err == nil {

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected