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