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

Function TestConstExpr_error_as_error

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

Source from the content-addressed store, hash-verified

1680}
1681
1682func TestConstExpr_error_as_error(t *testing.T) {
1683 env := map[string]any{
1684 "divide": func(a, b int) (int, error) {
1685 if b == 0 {
1686 return 0, divideError{"integer divide by zero"}
1687 }
1688 return a / b, nil
1689 },
1690 }
1691
1692 _, err := expr.Compile(
1693 `1 + divide(1, 0)`,
1694 expr.Env(env),
1695 expr.ConstExpr("divide"),
1696 )
1697 require.Error(t, err)
1698 require.Equal(t, "integer divide by zero", err.Error())
1699 require.IsType(t, divideError{}, err)
1700}
1701
1702func TestConstExpr_error_wrong_type(t *testing.T) {
1703 env := map[string]any{

Callers

nothing calls this directly

Calls 7

CompileFunction · 0.92
EnvStruct · 0.92
ConstExprFunction · 0.92
ErrorFunction · 0.92
EqualFunction · 0.92
IsTypeFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…