(t *testing.T)
| 188 | } |
| 189 | |
| 190 | func 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 | |
| 220 | func TestOperator_recursive_apply(t *testing.T) { |
| 221 | type Decimal struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…