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

Function TestFunction

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

Source from the content-addressed store, hash-verified

2099}
2100
2101func TestFunction(t *testing.T) {
2102 add := expr.Function(
2103 "add",
2104 func(p ...any) (any, error) {
2105 out := 0
2106 for _, each := range p {
2107 out += each.(int)
2108 }
2109 return out, nil
2110 },
2111 new(func(...int) int),
2112 )
2113
2114 p, err := expr.Compile(`add() + add(1) + add(1, 2) + add(1, 2, 3) + add(1, 2, 3, 4)`, add)
2115 assert.NoError(t, err)
2116
2117 out, err := expr.Run(p, nil)
2118 assert.NoError(t, err)
2119 assert.Equal(t, 20, out)
2120}
2121
2122// Nil coalescing operator
2123func TestRun_NilCoalescingOperator(t *testing.T) {

Callers

nothing calls this directly

Calls 5

FunctionFunction · 0.92
CompileFunction · 0.92
NoErrorFunction · 0.92
RunFunction · 0.92
EqualFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…