| 4571 | } |
| 4572 | |
| 4573 | func TestProgramContextEvalInvalidInput(t *testing.T) { |
| 4574 | env, err := NewEnv() |
| 4575 | if err != nil { |
| 4576 | t.Fatalf("NewEnv() failed: %v", err) |
| 4577 | } |
| 4578 | ast, iss := env.Compile("true") |
| 4579 | if iss.Err() != nil { |
| 4580 | t.Fatalf("Compile() failed: %v", iss.Err()) |
| 4581 | } |
| 4582 | prg, err := env.Program(ast) |
| 4583 | if err != nil { |
| 4584 | t.Fatalf("Program() failed: %v", err) |
| 4585 | } |
| 4586 | |
| 4587 | tests := []struct { |
| 4588 | name string |
| 4589 | ctx context.Context |
| 4590 | input any |
| 4591 | wantErr string |
| 4592 | }{ |
| 4593 | { |
| 4594 | name: "nil context", |
| 4595 | ctx: nil, |
| 4596 | input: map[string]any{}, |
| 4597 | wantErr: "context can not be nil", |
| 4598 | }, |
| 4599 | { |
| 4600 | name: "invalid input type", |
| 4601 | ctx: context.Background(), |
| 4602 | input: 123, |
| 4603 | wantErr: "invalid input, wanted Activation or map[string]any", |
| 4604 | }, |
| 4605 | } |
| 4606 | for _, tc := range tests { |
| 4607 | t.Run(tc.name, func(t *testing.T) { |
| 4608 | _, _, err := prg.ContextEval(tc.ctx, tc.input) |
| 4609 | if err == nil || !strings.Contains(err.Error(), tc.wantErr) { |
| 4610 | t.Errorf("ContextEval(%v, %v) err = %v, expected error containing %q", tc.ctx, tc.input, err, tc.wantErr) |
| 4611 | } |
| 4612 | }) |
| 4613 | } |
| 4614 | } |
| 4615 | |
| 4616 | func TestOptionalOperatorsLegacyEval(t *testing.T) { |
| 4617 | tests := []struct { |