Skip to content

Commit

Permalink
Add func(...any) (any, error) test
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Feb 2, 2023
1 parent e092ae3 commit 2992aac
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,22 @@ func TestFastCall(t *testing.T) {
assert.Equal(t, float64(8), out)
}

func TestFastCall_OpCallFastErr(t *testing.T) {
env := map[string]interface{}{
"func": func(...interface{}) (interface{}, error) {
return 8, nil
},
}
code := `func("8")`

program, err := expr.Compile(code, expr.Env(env))
assert.NoError(t, err)

out, err := expr.Run(program, env)
assert.NoError(t, err)
assert.Equal(t, 8, out)
}

func TestRun_custom_func_returns_an_error_as_second_arg(t *testing.T) {
env := map[string]interface{}{
"semver": func(value string, cmp string) (bool, error) { return true, nil },
Expand Down

0 comments on commit 2992aac

Please sign in to comment.