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

Function TestBlockEval_RuntimeErrors

ext/bindings_test.go:431–505  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

429}
430
431func TestBlockEval_RuntimeErrors(t *testing.T) {
432 fac := ast.NewExprFactory()
433 tests := []struct {
434 name string
435 expr ast.Expr
436 }{
437 {
438 name: "bad index",
439 expr: fac.NewCall(
440 1, "cel.@block",
441 fac.NewList(2, []ast.Expr{
442 fac.NewIdent(3, "x"),
443 fac.NewIdent(4, "@indexNext"),
444 }, []int32{}),
445 fac.NewCall(6, operators.Add,
446 fac.NewIdent(7, "@indexNext"),
447 fac.NewIdent(8, "@index0")),
448 ),
449 },
450 {
451 name: "infinite recursion",
452 expr: fac.NewCall(
453 1, "cel.@block",
454 fac.NewList(2, []ast.Expr{
455 fac.NewIdent(3, "@index0"),
456 fac.NewIdent(4, "@index0"),
457 }, []int32{}),
458 fac.NewIdent(10, "@index0"),
459 ),
460 },
461 {
462 name: "negative index",
463 expr: fac.NewCall(
464 1, "cel.@block",
465 fac.NewList(2, []ast.Expr{
466 fac.NewIdent(3, "@index-1"),
467 fac.NewIdent(4, "@index0"),
468 }, []int32{}),
469 fac.NewIdent(10, "@index0"),
470 ),
471 },
472 {
473 name: "out of range index",
474 expr: fac.NewCall(
475 1, "cel.@block",
476 fac.NewList(2, []ast.Expr{
477 fac.NewIdent(3, "@index100"),
478 fac.NewIdent(4, "@index0"),
479 }, []int32{}),
480 fac.NewIdent(10, "@index0"),
481 ),
482 },
483 }
484 for _, tst := range tests {
485 tc := tst
486 t.Run(tc.name, func(t *testing.T) {
487 blockAST := ast.NewAST(tc.expr, nil)
488 env, err := cel.NewEnv(

Callers

nothing calls this directly

Calls 13

NewCallMethod · 0.95
NewListMethod · 0.95
NewIdentMethod · 0.95
PlanProgramMethod · 0.95
NewExprFactoryFunction · 0.92
NewASTFunction · 0.92
NewEnvFunction · 0.92
VariableFunction · 0.92
BindingsFunction · 0.85
BindingsVersionFunction · 0.85
EvalMethod · 0.65
ContainsMethod · 0.65

Tested by

no test coverage detected