| 5337 | } |
| 5338 | |
| 5339 | func TestProgramContextEvalInvalidInput(t *testing.T) { |
| 5340 | env, err := NewEnv() |
| 5341 | if err != nil { |
| 5342 | t.Fatalf("NewEnv() failed: %v", err) |
| 5343 | } |
| 5344 | ast, iss := env.Compile("true") |
| 5345 | if iss.Err() != nil { |
| 5346 | t.Fatalf("Compile() failed: %v", iss.Err()) |
| 5347 | } |
| 5348 | prg, err := env.Program(ast) |
| 5349 | if err != nil { |
| 5350 | t.Fatalf("Program() failed: %v", err) |
| 5351 | } |
| 5352 | |
| 5353 | tests := []struct { |
| 5354 | name string |
| 5355 | ctx context.Context |
| 5356 | input any |
| 5357 | wantErr string |
| 5358 | }{ |
| 5359 | { |
| 5360 | name: "nil context", |
| 5361 | ctx: nil, |
| 5362 | input: map[string]any{}, |
| 5363 | wantErr: "context can not be nil", |
| 5364 | }, |
| 5365 | { |
| 5366 | name: "invalid input type", |
| 5367 | ctx: context.Background(), |
| 5368 | input: 123, |
| 5369 | wantErr: "invalid input, wanted Activation or map[string]any", |
| 5370 | }, |
| 5371 | } |
| 5372 | for _, tc := range tests { |
| 5373 | t.Run(tc.name, func(t *testing.T) { |
| 5374 | _, _, err := prg.ContextEval(tc.ctx, tc.input) |
| 5375 | if err == nil || !strings.Contains(err.Error(), tc.wantErr) { |
| 5376 | t.Errorf("ContextEval(%v, %v) err = %v, expected error containing %q", tc.ctx, tc.input, err, tc.wantErr) |
| 5377 | } |
| 5378 | }) |
| 5379 | } |
| 5380 | } |
| 5381 | |
| 5382 | func TestOptionalOperatorsLegacyEval(t *testing.T) { |
| 5383 | tests := []struct { |