| 2502 | } |
| 2503 | |
| 2504 | func TestIssue474(t *testing.T) { |
| 2505 | testCases := []struct { |
| 2506 | code string |
| 2507 | fail bool |
| 2508 | }{ |
| 2509 | { |
| 2510 | code: `func("invalid")`, |
| 2511 | fail: true, |
| 2512 | }, |
| 2513 | { |
| 2514 | code: `func(true)`, |
| 2515 | fail: true, |
| 2516 | }, |
| 2517 | { |
| 2518 | code: `func([])`, |
| 2519 | fail: true, |
| 2520 | }, |
| 2521 | { |
| 2522 | code: `func({})`, |
| 2523 | fail: true, |
| 2524 | }, |
| 2525 | { |
| 2526 | code: `func(1)`, |
| 2527 | fail: false, |
| 2528 | }, |
| 2529 | { |
| 2530 | code: `func(1.5)`, |
| 2531 | fail: false, |
| 2532 | }, |
| 2533 | } |
| 2534 | |
| 2535 | for _, tc := range testCases { |
| 2536 | ltc := tc |
| 2537 | t.Run(ltc.code, func(t *testing.T) { |
| 2538 | t.Parallel() |
| 2539 | function := expr.Function("func", func(params ...any) (any, error) { |
| 2540 | return true, nil |
| 2541 | }, new(func(float64) bool)) |
| 2542 | _, err := expr.Compile(ltc.code, function) |
| 2543 | if ltc.fail { |
| 2544 | if err == nil { |
| 2545 | t.Error("expected an error, but it was nil") |
| 2546 | t.FailNow() |
| 2547 | } |
| 2548 | } else { |
| 2549 | if err != nil { |
| 2550 | t.Errorf("expected nil, but it was %v", err) |
| 2551 | t.FailNow() |
| 2552 | } |
| 2553 | } |
| 2554 | }) |
| 2555 | } |
| 2556 | } |
| 2557 | |
| 2558 | func TestRaceCondition_variables(t *testing.T) { |
| 2559 | program, err := expr.Compile(`let foo = 1; foo + 1`, expr.Env(mock.Env{})) |