MCPcopy Index your code
hub / github.com/expr-lang/expr / TestOperator_recursive_apply

Function TestOperator_recursive_apply

test/operator/operator_test.go:220–255  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

218}
219
220func TestOperator_recursive_apply(t *testing.T) {
221 type Decimal struct {
222 Int int
223 }
224
225 env := map[string]any{
226 "add": func(a, b Decimal) Decimal {
227 return Decimal{
228 Int: a.Int + b.Int,
229 }
230 },
231 "addInt": func(a Decimal, b int) Decimal {
232 return Decimal{
233 Int: a.Int + b,
234 }
235 },
236 "a": Decimal{1},
237 "b": Decimal{2},
238 "c": Decimal{3},
239 "d": Decimal{4},
240 "e": Decimal{5},
241 }
242
243 program, err := expr.Compile(
244 `a + b + 100 + c + d + e`,
245 expr.Env(env),
246 expr.Operator("+", "add"),
247 expr.Operator("+", "addInt"),
248 )
249 require.NoError(t, err)
250 require.Equal(t, `add(add(add(addInt(add(a, b), 100), c), d), e)`, program.Node().String())
251
252 output, err := expr.Run(program, env)
253 require.NoError(t, err)
254 require.Equal(t, 115, output.(Decimal).Int)
255}

Callers

nothing calls this directly

Calls 8

CompileFunction · 0.92
EnvStruct · 0.92
OperatorFunction · 0.92
NoErrorFunction · 0.92
EqualFunction · 0.92
RunFunction · 0.92
NodeMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…