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

Function TestMaxExpressionNodeCount

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

Source from the content-addressed store, hash-verified

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