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

Function TestOperator_Polymorphic

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

Source from the content-addressed store, hash-verified

188}
189
190func TestOperator_Polymorphic(t *testing.T) {
191 env := struct {
192 Add func(a, b int) int
193 Foo Value
194 Bar Value
195 }{
196 Add: func(a, b int) int {
197 return a + b
198 },
199 Foo: Value{1},
200 Bar: Value{2},
201 }
202
203 program, err := expr.Compile(
204 `1 + 2 + (Foo + Bar)`,
205 expr.Env(env),
206 expr.Operator("+", "Add", "AddValues"),
207 expr.Function("AddValues", func(args ...interface{}) (interface{}, error) {
208 return args[0].(Value).Int + args[1].(Value).Int, nil
209 },
210 new(func(_ Value, __ Value) int),
211 ),
212 )
213 require.NoError(t, err)
214
215 output, err := expr.Run(program, env)
216 require.NoError(t, err)
217 require.Equal(t, 6, output)
218}
219
220func TestOperator_recursive_apply(t *testing.T) {
221 type Decimal struct {

Callers

nothing calls this directly

Calls 7

CompileFunction · 0.92
EnvStruct · 0.92
OperatorFunction · 0.92
FunctionFunction · 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…