MCPcopy
hub / github.com/expr-lang/expr / TestIssue474

Function TestIssue474

expr_test.go:2504–2556  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2502}
2503
2504func 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
2558func TestRaceCondition_variables(t *testing.T) {
2559 program, err := expr.Compile(`let foo = 1; foo + 1`, expr.Env(mock.Env{}))

Callers

nothing calls this directly

Calls 6

FunctionFunction · 0.92
CompileFunction · 0.92
RunMethod · 0.80
FailNowMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…