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

Function TestBlockEval_RuntimeErrors

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

Source from the content-addressed store, hash-verified

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