(t *testing.T)
| 218 | } |
| 219 | |
| 220 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…