(t *testing.T)
| 429 | } |
| 430 | |
| 431 | func 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( |
nothing calls this directly
no test coverage detected